linux获取文件全路径的方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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



本文出自 “残剑” 博客,请务必保留此出处http://cuidehua.blog.51cto.com/5449828/1961186

以上是关于linux获取文件全路径的方法的主要内容,如果未能解决你的问题,请参考以下文章