bash 如何使用linux命令获取路径的一部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7065805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:35:48 来源:igfitidea点击:
How to get part of path using linux commands
提问by Roman
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.
需要获取路径的一部分,例如“/home/server/folder1/rev.1111/bin”需要的部分是“rev.1111”我会尝试通过 PWD 和 grep 命令解析,但我是 linux 新手,我不能这样做。
回答by Sean Bright
pwd | awk -F/ '{print $(NF-1)}'
回答by Nicolae Dascalu
Using the basename & dirname commands:
使用 basename 和 dirname 命令:
basename $(dirname $(pwd))

