How to get full path of a file?

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 <command>

dir> <command> file.txt  

should print

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

使用readlink

readlink -f file.txt

I suppose you are using Linux.

I found a utility called realpath in coreutils 8.15.

realpath realpath
/data/ail_data/transformed_binaries/coreutils/test_folder_realpath/realpath

以下通常会做诀窍:

 echo $(cd $(dirname "$1") && pwd -P)/$(basename "$1")
链接地址: http://www.djcxy.com/p/9738.html

上一篇: 总是在bash中获取相关文件的完整路径

下一篇: 如何获得文件的完整路径?