Unix - copy contents of one directory to another

Folder1/
-fileA.txt
-fileB.txt
-fileC.txt


> mkdir Folder2/


> [copy command]

And now Folder2/ looks like:

Folder2/
-fileA.txt
-fileB.txt
-fileC.txt

How to make this happen? I have tried cp -r Folder1/ Folder2/ but I ended up with:

Folder2/
Folder1/
-fileA.txt
-fileB.txt
-fileC.txt

Which is close but not exactly what I wanted.

Thanks!

263101 次浏览

Quite simple, with a * wildcard.

cp -r Folder1/* Folder2/

But according to your example recursion is not needed so the following will suffice:

cp Folder1/* Folder2/

EDIT:

Or skip the mkdir Folder2 part and just run:

cp -r Folder1 Folder2

Try this:

cp Folder1/* Folder2/

To make an exact copy, permissions, ownership, and all use "-a" with "cp". "-r" will copy the contents of the files but not necessarily keep other things the same.

cp -av Source/* Dest/

(make sure Dest/ exists first)

If you want to repeatedly update from one to the other or make sure you also copy all dotfiles, rsync is a great help:

rsync -av --delete Source/ Dest/

This is also "recoverable" in that you can restart it if you abort it while copying. I like "-v" because it lets you watch what is going on but you can omit it.