How to get full path of a file?

后端 未结 30 3324
走了就别回头了
走了就别回头了 2020-12-02 03:22

Is there an easy way I can print the full path of file.txt ?

file.txt = /nfs/an/disks/jj/home/dir/file.txt

The

30条回答
  •  猫巷女王i
    2020-12-02 03:50

    find / -samefile file.txt -print
    

    Will find all the links to the file with the same inode number as file.txt

    adding a -xdev flag will avoid find to cross device boundaries ("mount points"). (But this will probably cause nothing to be found if the find does not start at a directory on the same device as file.txt)

    Do note that find can report multiple paths for a single filesystem object, because an Inode can be linked by more than one directory entry, possibly even using different names. For instance:

    find /bin -samefile /bin/gunzip -ls
    

    Will output:

    12845178    4 -rwxr-xr-x   2 root     root         2251 feb  9  2012 /bin/uncompress
    12845178    4 -rwxr-xr-x   2 root     root         2251 feb  9  2012 /bin/gunzip
    

提交回复
热议问题