How to get part of path using linux commands

孤者浪人 提交于 2019-12-19 07:23: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))


来源:https://stackoverflow.com/questions/7065805/how-to-get-part-of-path-using-linux-commands

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!