我想只列出指定路径中的目录(ls没有这样的选项)。 另外,这可以用单行命令完成吗?


当前回答

### If you need full path of dir and list selective dir with "name" of dir(or dir_prefix*):
find $(pwd) -maxdepth 1 -type d -name "SL*"

其他回答

### If you need full path of dir and list selective dir with "name" of dir(or dir_prefix*):
find $(pwd) -maxdepth 1 -type d -name "SL*"

使用这个来获得目录列表

ls -d */ | sed -e "s/\///g"

为了列出当前工作目录中的目录 Ls -d */可以使用。 如果需要列出隐藏目录,则使用此命令 Ls -d .*/

既然有几十种方法可以做到这一点,下面是另一种方法:

tree -d -L 1 -i --noreport

- d:目录 -L:树的深度(因此1是我们的工作目录) -i:不缩进,只打印名称 ——noreport:不报告树列表末尾的信息

可以使用ls -d */或tree -d

另一种解决方案是通配符,但这取决于您正在使用的shell以及是否支持目录通配符。

例如ZSH:

zsh # ls *(/)