linux获取文件全路径的方法

获取路径的各种相关方法:

获取文件名:

basename /home/cuizhiliang344/note.txt

note.txt


获取目录:

dirname /home/cuizhiliang344/note.txt

/home/cuizhiliang344


通过一个文件获取全路径


方法一:

readlink -f  note.txt

/home/cuizhiliang344/note.txt

方法二:

python -c 'import os; print(os.path.abspath("note.txt"))'

方法三:

ls $PWD/note.txt

本文转自残剑博客51CTO博客,原文链接http://blog.51cto.com/cuidehua/1961186如需转载请自行联系原作者


cuizhiliang

你可能感兴趣的:(linux获取文件全路径的方法)