DISQUS

Tech-Recipes: Copy entire contents of a directory and preserve permissions | Solaris | Tech-Recipes

  • fall-line · 5 years ago
    what's wrong with cp -Rp dir1 dir2 ?
  • Anonymous · 5 years ago
    'cp -Rp' is not supported on most Unixes. '-Rp' flags are only supported by the version of 'ls' that comes with the GNU Core-utils, which is not installed everywhere.

    The tar command will work on all versions of Unix.
  • Anonymous · 5 years ago
    In addition, I think you meant 'cp -a', which is equivilant to 'cp -dpR'. The -d flag will dereference symbolic links.

    'cp -Rp dir1 dir2' doesn't preserve symlinks. It will instead copy the contents of the target:


    If dir1 looks like this:


    -rw-r--r-- 1 flarg group 0 Aug 17 14:59 file1
    lrwxrwxrwx 1 flarg group 4 Aug 17 14:59 link1 -> /tmp



    If you use 'cp -Rp', then 'link1' will become a directory:


    cp -Rp dir1 dir2
    -rw-r--r-- 1 flarg group 0 Aug 17 14:59 file1
    drwxrwxrwx 7 flarg groupl 1701 Aug 17 14:59 link1



    You really want the '-d' flag to dereference any symbolic links.
  • Anonymous · 5 years ago
    <ul id="quote"><h6>flarg wrote:</h6>In addition, I think you meant 'cp -a', which is equivilant to 'cp -dpR'. The -d flag will dereference symbolic links.

    'cp -Rp dir1 dir2' doesn't preserve symlinks. It will instead copy the contents of the target:


    If dir1 looks like this:


    -rw-r--r-- 1 flarg group 0 Aug 17 14:59 file1
    lrwxrwxrwx 1 flarg group 4 Aug 17 14:59 link1 -> /tmp



    If you use 'cp -Rp', then 'link1' will become a directory:


    cp -Rp dir1 dir2
    -rw-r--r-- 1 flarg group 0 Aug 17 14:59 file1
    drwxrwxrwx 7 flarg groupl 1701 Aug 17 14:59 link1



    You really want the '-d' flag to dereference any symbolic links.</ul>
  • joppe Koning · 5 years ago
    cp uses a caracter for caracter copy method. copying with tar is faster because is uses greater buffers