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!

0

3 Answers 3

129

Try this:

cp Folder1/* Folder2/
7
  • 3
    but this won't copy hidden files, right? Jan 29, 2014 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, 2014 at 0: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 Sep 15, 2014 at 19:49
  • note that SCP has a slightly different syntax, see here: stackoverflow.com/a/26346339/1984636
    – sivi
    Feb 4, 2016 at 8:35
  • 1
    Don't do this. Do "cp -rT src dest" on Linux, or "cp -R src/ dest" on BSD. Aug 5, 2020 at 10:56
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
2
  • If ls | sort -k1.5 | head -8 > folder1 then how to do that ?
    – Pooja
    Apr 4, 2013 at 4:49
  • 1
    You just lost all your hidden files. Don't do this. Do "cp -rT src dest" on Linux, or "cp -R src/ dest" on BSD. Aug 5, 2020 at 10:57
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.

5
  • 1
    what is the -v for?
    – HattrickNZ
    Jun 23, 2014 at 0:53
  • verbose, just to watch what is going on. Jun 23, 2014 at 1:05
  • 1
    If you have a lot of files the -v option can take some time. If you don't need the output use -a only.
    – Eyal Levin
    Nov 24, 2016 at 13:32
  • 1
    You'd have to be running over pretty slow network connection for the copy to be slowed by text output. And even then, it would likely just be the return of the command prompt, not the copy itself. Nov 26, 2016 at 2:10
  • You lost your hidden files. Do "cp -rT src dest" on Linux, or "cp -R src/ dest" on BSD. Aug 5, 2020 at 10:57

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