Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    copying simbolic links in linux

    Hello Peoples:

    I would like to know if it is possible to copy a simbolic link in linux.
    I am trying to copy a link from my internal hard drive to an external-usb hard drive for backup purposes.


  2. #2
    Just Joined!
    Join Date
    Nov 2007
    The option you search is:

    -d, --no-dereference

    But there is also an option -a which is for backup, cause it keeps symbolic Links, it keeps the file attributes (very important), and it does so recursively; so like:
    cp -dpR


    P.S.: I needed just about 5 seconds to look that up in the manpage^ (Besides that i knew it alreaady)

  3. #3
    cpio does it nicely - much underused utility:
    cpio <inputfilelist -pvdum targetdir
    You can pipe find's output in instead of using an inputlist, or just echo a single file name if that's all you need.
    cd /home/myhome; find . -print -depth | cpio -pvdum newhomedir

  4. $spacer_open
  5. #4
    Hello there:

    Thanks a lot Ogion and scm. I already have one more command at my disposal.
    It is really doing the copying of symbolic links.

  6. #5
    [root@willie backup]# find . -print | cpio -o > archive.cpio
    cpio: .: truncating inode number
    cpio: test1: truncating inode number
    cpio: logo2Lynk.png: truncating inode number
    cpio: test2: truncating inode number
    cpio: archive.cpio: truncating inode number
    1 block
    [root@willie backup]# ls
    archive.cpio logo2Lynk.png test1 test2
    [root@willie backup]# mv archive.cpio ../
    [root@willie backup]# ls
    fslogo2Lynk.png test1 test2
    [root@willie backup]# ls -a
    total 8
    lrwxrwxrwx 1 root root 24 Dec 12 12:35 logo2Lynk.png -> /home/willie/logo.png
    -rw-r--r-- 1 willie willie 37 Nov 28 17:43 test1
    -rw-r--r-- 1 willie willie 36 Nov 28 17:44 test2
    [root@willie backup]# rm -rf *
    [root@willie backup]# ls
    [root@willie willie]# cd backup/
    [root@willie backup]# ll
    total 0
    (I just want to restore the .png files from my archive backup to my backup directory. see below):
    [root@willie backup]# cpio -i "*.png" < /home/willie/archive.cpio
    1 block
    [root@willie backup]# ll
    total 0
    lrwxrwxrwx 1 root root 24 Dec 12 13:40 fslogo2Lynk.png -> /home/willie/fslogo2.png
    [root@willie backup]#

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts