How to get part of path using linux commands

2019-02-17 05:14发布

问题:

Need get part of path, for example "/home/server/folder1/rev.1111/bin" Needed part is "rev.1111" I`ll try to parse by PWD & grep commands, but I am newbie on linux and I cant do this.

回答1:

pwd | awk -F/ '{print $(NF-1)}'


回答2:

Using the basename & dirname commands:

basename $(dirname $(pwd))


标签: bash path get pwd