Listing only directories in UNIX

前端 未结 20 883
青春惊慌失措
青春惊慌失措 2020-12-12 09:40

I want to list only the directories in specified path (ls doesn\'t have such option). Also, can this be done with a single line command?

20条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 10:06

    If I have this directory:

    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
    

    To get all directories, use -L to resolve links:

    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
    

    Without -L:

    ls -l | grep '^d'

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

    conf_nagios directory is missing.

提交回复
热议问题