有一个在Linux命令行工具,将“正常化”一个文件名? 即删除所有“xx /./ xx”部分,或“myfolder /../ myotherfolder”部分?
其实它是实时path: http : //linux.about.com/library/cmd/blcmdl3_realpath.htm
还有一个命令行版本:cyberciti.biz/faq/unix-linux-bsd-find-real-physical-path/
但在我的CentOS 5上,它默认是不可用的。
还有一种“作弊的方式”:
$ bash -c "cd /foo/../bar/ ; pwd" /bar
readlink -f似乎这样做(尽pipe是为了去引用符号链接):
[root@noldevvg19 ~]# readlink -f /etc/../usr/../etc/./sysconfig/../redhat-release /etc/redhat-release
我相信这就是所谓的“规范化”。
你是要求basename命令吗?
$ basename ../../.bashrc .bashrc
还有另一部分:dirname
$ dirname ../../.bashrc ../..
用python命令行:
python -c 'import os; print os.path.basename("/home/mezgani/nat")' python -c 'import os; print os.path.direname("/home/mezgani/nat")'