Linux 使用 ls 列出子目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5168071/
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 sub-directories with ls
提问by Bernhard
How could I list sub-directories with ls, with '-d' only the current directory is shown. I want something like find . -type d -maxdepth 1
would give me.
如何使用 ls 列出子目录,使用“-d”仅显示当前目录。我想要一些像find . -type d -maxdepth 1
会给我的东西。
采纳答案by Costi Ciudatu
This should help:
这应该有帮助:
ls -d */
ls -d */
*/
will only match directories under the current dir. The output directory names will probably contain the trailing '/' though.
*/
只会匹配当前目录下的目录。不过,输出目录名称可能会包含结尾的“/”。
回答by ?imon Tóth
ls -d */
and ls -d */*/
seem to work just fine.
ls -d */
并且ls -d */*/
似乎工作得很好。
回答by dogbane
You can combine with grep:
您可以与 grep 结合使用:
ls -l | grep '^d'
To get just the filenames:
只获取文件名:
ls -l | grep '^d' | awk '{ print }'
You can make this into a handy alias:
你可以把它变成一个方便的别名:
alias ldir="ls -l | grep '^d'"