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


当前回答

find . -maxdepth 1 -type d -name [^\.]\* | sed 's:^\./::'

其他回答

### 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*"
find . -maxdepth 1 -type d -name [^\.]\* | sed 's:^\./::'

目录长列表

ls -l | grep  '^d'  

清单目录

ls -d */

如果我有这个目录:

ls -l

lrwxrwxrwx  1 nagios nagios     11 août   2 18:46 conf_nagios -> /etc/icinga
-rw-------  1 nagios nagios 724930 août  15 21:00 dead.letter
-rw-r--r--  1 nagios nagios  12312 août  23 00:13 icinga.log
-rw-r--r--  1 nagios nagios   8323 août  23 00:12 icinga.log.gz
drwxr-xr-x  2 nagios nagios   4096 août  23 16:36 tmp

要获取所有目录,使用-L解析链接:

ls -lL | grep '^d'

drwxr-xr-x 5 nagios nagios   4096 août  15 21:22 conf_nagios
drwxr-xr-x 2 nagios nagios   4096 août  23 16:41 tmp

没有- l:

Ls -l | grep '^d'

drwxr-xr-x 2 nagios nagios   4096 août  23 16:41 tmp

Conf_nagios目录缺失。

尝试使用ls -d */来列出当前目录中的目录