user710818
user710818

Reputation: 24248

How to copy in bash all directory and files recursive?

I have script:

find ./SourceFolder/ -maxdepth 4 -exec cp -R '{}' ./DestFolder/ \;

SourceDir contains also sub-folders.

Problem that in DestFolder not only all tree, but in up level all another levels and files.

How to fix ?

Upvotes: 241

Views: 275993

Answers (4)

dbcookie
dbcookie

Reputation: 211

also try this cp -r ./dist/* ./out;

this command will copy dist/* files to out dir;

Upvotes: 17

Harry Bosh
Harry Bosh

Reputation: 3790

You might find it handy to keep your attributes set

cp -arf ./SourceFolder ./DestFolder

Upvotes: 6

shamimiceewu025
shamimiceewu025

Reputation: 881

code for a simple copy.

cp -r ./SourceFolder ./DestFolder

code for a copy with success result

cp -rv ./SourceFolder ./DestFolder

code for Forcefully if source contains any readonly file it will also copy

cp -rf ./SourceFolder ./DestFolder

for details help

cp --help

Upvotes: 78

lanzz
lanzz

Reputation: 43158

cp -r ./SourceFolder ./DestFolder

Upvotes: 447

Related Questions