提取pwd输出的最后一个目录 [英] Extract the last directory of a pwd output
本文介绍了提取pwd输出的最后一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何提取pwd输出的最后一个目录?我不想使用任何有关目录结构中有多少层的知识.如果我想使用它,我可以做类似的事情:
How do I extract the last directory of a pwd output? I don't want to use any knowledge of how many levels there are in the directory structure. If I wanted to use that, I could do something like:
> pwd
/home/kiki/dev/my_project
> pwd | cut -d'/' -f5
my_project
但是我想使用一个无论我在目录结构中的位置如何都起作用的命令.我假设有一个简单的命令可以使用awk或sed来完成此操作.
But I want to use a command that works regardless of where I am in the directory structure. I assume there is a simple command to do this using awk or sed.
推荐答案
类似
basename "`pwd`"
应该是您想知道的.
如果您坚持使用sed
,也可以使用
If you insist on using sed
, you could also use
pwd | sed 's#.*/##'
这篇关于提取pwd输出的最后一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文