Linux Shell - How to copy directory without symlink

16,271

Solution 1

Run this command

find (Old dir) -depth -type f -o -type d | cpio -pamVd /New/Directory

it will only copy files and directories, but not symlinks

Example:

find . -depth -type f -o -type d | cpio -pamVd /root/mydir

this will recursively copy all the file/directories from current directory to /root/mydir

Solution 2

Or simply copy everything, then delete the symlinks.

cp -R /path/source /path/dest; find /path/dest -type l -exec rm -f {} \;
Share:
16,271

Related videos on Youtube

Julio Fong
Author by

Julio Fong

Updated on September 18, 2022

Comments

  • Julio Fong
    Julio Fong over 1 year

    I would like to get everything inside one directory.

    How can I copy entire directory (that originally contains files and symlinks) to a new directory that should contains all files but no symlink??

    Thank you

    • Nirav Limbasiya
      Nirav Limbasiya over 11 years
      do a small bash script
    • Julio Fong
      Julio Fong over 11 years
      lol, this is not the question
  • philcolbourn
    philcolbourn about 10 years
    does OP want symlinks converted into files or just ignored?
  • Farhan
    Farhan about 10 years
    not sure about that