Parsa
Parsa

Reputation: 3236

Unix Copy Recursive Including All Directories

I have the following two directories:

~/A
    drawable/
        imageb.png
    new/`
        newimage.png

~/B
    drawable/
        imagec.png

When I use the cp -r ~/A/* ~/B command newimage.png with its new/ folder is copied across to ~/B however imageb.png is not copied into ~/B/drawable.

Could you explain why this is the case and how I can get around this?

Upvotes: 0

Views: 112

Answers (2)

askmish
askmish

Reputation: 6674

If you are on linux you can use the -r option.

eg: cp -r ~/A/. ~/B/

If you are on BSD you could use the -R option.

eg: cp -R ~/A/. ~/B/

For more information on exactly what option you should pass, refer man cp

Also note that, if you do not have permissions to the file you it would prevent copying files.

Upvotes: 1

RSD3
RSD3

Reputation: 26

Use tar instead of cp:

(cd A ; tar cf - *) | (cd B ; tar xf -)

or more compactly (if you're using GNU tar):

tar cC A -f - . | tar xC B -f -

Upvotes: 1

Related Questions