One - One Code All

Blog Content

Linux shell获得当前目录、上级目录、目录的最后部分

Linux-Mac   2017-08-05 14:45:49


当前目录


current_path="$PWD"  # 同 "`pwd`"


上一级目录


path=$(dirname "$PWD")


上上级目录 (原理同上)


path=$(dirname $(dirname "$PWD"))


目录的最后部分


last_component=$(basename "$PWD")



上一篇:centos下修改/etc/hosts文件以及生效命令
下一篇:在Mac上删除自己安装的Python

The minute you think of giving up, think of the reason why you held on so long.