92
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!

Czechnology
  • 14,832
  • 10
  • 62
  • 88
JDS
  • 16,388
  • 47
  • 161
  • 224

3 Answers3

129

Try this:

cp Folder1/* Folder2/
Geoff
  • 2,461
  • 2
  • 24
  • 42
  • 3
    but this won't copy hidden files, right? – Fabrizio Regini Jan 29 '14 at 10:35
  • 9
    Correct. `cp -R` will, but that'll recursively copy, so you may or may not want to use that. You could do `cp Folder1/.* Folder2/` to copy only the hidden files. – Geoff Jan 30 '14 at 00:12
  • 2
    Note that this will fail if you are using "sudo" or an equivalent and the directory contains a lot of files. I get `sudo: unable to execute /bin/cp: Argument list too long` – Nathan Osman Sep 15 '14 at 19:49
  • note that SCP has a slightly different syntax, see here: http://stackoverflow.com/a/26346339/1984636 – sivi Feb 04 '16 at 08:35
  • Don't do this. Do "cp -rT src dest" on Linux, or "cp -R src/ dest" on BSD. – xpusostomos Aug 05 '20 at 10:56
  • @xpusostomos why? – tonitone120 Nov 05 '20 at 16:57
  • @tonitone because using shell glob, aka "*" does not match hidden files, i.e. files starting with dot. Also, a very large directory could exceed the glob memory space, although that's rare. – xpusostomos Nov 08 '20 at 07:48
50

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
Koen.
  • 25,449
  • 7
  • 83
  • 78
23

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.

Brian White
  • 8,332
  • 2
  • 43
  • 67