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/
Sign up to request clarification or add additional context in comments.

7 Comments

but this won't copy hidden files, right?
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.
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
note that SCP has a slightly different syntax, see here: stackoverflow.com/a/26346339/1984636
Don't do this. Do "cp -rT src dest" on Linux, or "cp -R src/ dest" on BSD.
|
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 Comments

If ls | sort -k1.5 | head -8 > folder1 then how to do that ?
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.
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 Comments

what is the -v for?
verbose, just to watch what is going on.
If you have a lot of files the -v option can take some time. If you don't need the output use -a only.
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.
You lost your hidden files. Do "cp -rT src dest" on Linux, or "cp -R src/ dest" on BSD.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.