How to get full path of a file?

后端 未结 30 3334
走了就别回头了
走了就别回头了 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条回答
  •  囚心锁ツ
    2020-12-02 04:06

    I suppose you are using Linux.

    I found a utility called realpath in coreutils 8.15.

    realpath file.txt
    /data/ail_data/transformed_binaries/coreutils/test_folder_realpath/file.txt
    

    As per @styrofoam-fly and @arch-standton comments, realpath alone doesn't check for file existence, to solve this add the e argument: realpath -e file

提交回复
热议问题