How to copy in bash all directory and files recursive?

BashCopyDirectory

Bash Problem Overview


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 ?

Bash Solutions


Solution 1 - Bash

cp -r ./SourceFolder ./DestFolder

Solution 2 - Bash

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

Solution 3 - Bash

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

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

Solution 4 - Bash

You might find it handy to keep your attributes set

cp -arf ./SourceFolder ./DestFolder

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser710818View Question on Stackoverflow
Solution 1 - BashlanzzView Answer on Stackoverflow
Solution 2 - Bashshamimiceewu025View Answer on Stackoverflow
Solution 3 - BashdbcookieView Answer on Stackoverflow
Solution 4 - BashHarry BoshView Answer on Stackoverflow