8

I have a directory dir1 and it contains a lot of files and directories and also I have another directory dir2 and it is empty. And I need a linux command to move the dir1 with all the files and folders into dir2. The result should be like that dir2/dir1/...

I found the mv command, but it moves a file from a directory to another directory and I don't want that. Thank you!

3 Answers 3

11

mv command can move directories also.

Sign up to request clarification or add additional context in comments.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
mv dir1/ dir2/ would be a more sufficient answer
6

Use cp with -r to copy content along with the folder recursively

 cp -r dir1 dir2/

Then remove the folder if u want (double check if u copied all the files LOL before removing)

 rm -r dir1

1 Comment

Better answer IMO: Especially considering that the Top Result on Google Search is WRONG. And with their partnership with Reddit, I suspect that things will continually get worse, since Reddit locks their threads, thereby preventing the correction of misinformation and outdated information (as technology changes & advances).
1

Expanding on @Dhruv's answer, you can simply do mv dir1 dir2. It will move all the contents of dir1 into dir2 including subdirectories.

2 Comments

mv dir1 dir2 does not move the contents of dir1 in dir2. Instead, it moves dir1 inside dir2.
To move all content from dir1 into dir2 use: mv dir1/ dir2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.