bash 仅列出与模式匹配的目录名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15486373/
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
List only directories names which match a pattern
提问by Jorge Vega Sánchez
I'm bit confused about the command or modifiers to obtain: List of directories (only directories, not including subdirectories) which names include a pattern.
我对获取的命令或修饰符有点困惑:名称包含模式的目录列表(仅目录,不包括子目录)。
Thanks in advance.
提前致谢。
采纳答案by Jorge Vega Sánchez
That's works for me.
这对我有用。
But it outputs also the directory characteristics, permissions, date, etc. and I want to display only the directory name.
但它也输出目录特征、权限、日期等,我只想显示目录名称。
ls -t | grep '^d' | grep 'pattern'
回答by choroba
You are probably after the -d
switch of ls
:
您可能正在-d
切换ls
:
ls -d *pattern*/
ls --directory *pattern*/