How to see full symlink path

后端 未结 5 1333
悲&欢浪女
悲&欢浪女 2020-12-22 21:15

When I\'m using ls -la symlinkName or stat symlinkName not all the path is displayed (e.g ../../../one/two/file.txt)

What is

相关标签:
5条回答
  • 2020-12-22 21:56

    You can use awk with a system call readlink to get the equivalent of an ls output with full symlink paths. For example:

    ls | awk '{printf("%s ->", $1); system("readlink -f " $1)}'
    

    Will display e.g.

    thin_repair ->/home/user/workspace/boot/usr/bin/pdata_tools
    thin_restore ->/home/user/workspace/boot/usr/bin/pdata_tools
    thin_rmap ->/home/user/workspace/boot/usr/bin/pdata_tools
    thin_trim ->/home/user/workspace/boot/usr/bin/pdata_tools
    touch ->/home/user/workspace/boot/usr/bin/busybox
    true ->/home/user/workspace/boot/usr/bin/busybox
    
    0 讨论(0)
  • 2020-12-22 22:08

    realpath <path to the symlink file> should do the trick.

    0 讨论(0)
  • 2020-12-22 22:09

    realpath isn't available on all linux flavors, but readlink should be.

    readlink -f symlinkName
    

    The above should do the trick.

    Alternatively, if you don't have either of the above installed, you can do the following if you have python 2.6 (or later) installed

    python -c 'import os.path; print(os.path.realpath("symlinkName"))'
    
    0 讨论(0)
  • 2020-12-22 22:10

    unix flavors -> ll symLinkName

    OSX -> readlink symLinkName

    Difference is 1st way would display the sym link path in a blinking way and 2nd way would just echo it out on the console.

    0 讨论(0)
  • 2020-12-22 22:10

    Another way to see information is stat command that will show more information. Command stat ~/.ssh on my machine display

    File: ‘/home/sumon/.ssh’ -> ‘/home/sumon/ssh-keys/.ssh.personal’
      Size: 34          Blocks: 0          IO Block: 4096   symbolic link
    Device: 801h/2049d  Inode: 25297409    Links: 1
    Access: (0777/lrwxrwxrwx)  Uid: ( 1000/   sumon)   Gid: ( 1000/   sumon)
    Access: 2017-09-26 16:41:18.985423932 +0600
    Modify: 2017-09-25 15:48:07.880104043 +0600
    Change: 2017-09-25 15:48:07.880104043 +0600
     Birth: -
    

    Hope this may help someone.

    0 讨论(0)
提交回复
热议问题