Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have two directories that look like this:

/folder1/sub1/file1.txt
/folder1/sub1/file2.txt
/folder1/sub2/file1.txt
/folder1/sub2/file2.txt

/folder2/sub1/file3.txt
/folder2/sub1/file4.txt
/folder2/sub2/file3.txt
/folder2/sub2/file4.txt

I'd like to copy all of the files from folder2 into folder1 without deleting any of the existing folders, so that I end up with the following:

/folder1/sub1/file1.txt
/folder1/sub1/file2.txt
/folder1/sub1/file3.txt
/folder1/sub1/file4.txt
/folder1/sub2/file1.txt
/folder1/sub2/file2.txt
/folder1/sub2/file3.txt
/folder1/sub2/file4.txt

how can I accomplish this via the terminal?

share|improve this question

1 Answer 1

rsync is a perfect tool for this job:

rsync -av folder2/ folder1

The -v option is optional, but it lists files as they're processed. The slash after folder2 is required, otherwise you'll get folder1/folder2/file1.txt instead of folder1/file1.txt.

If you're not sure whether the command does what you want, add the --dry-run option to show what would actually happen.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.