5

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?

1 Answer 1

9

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .