Linux – list only directories

Sometimes we need to list only directories on Linux (or any other unix). Here are some approaches.

  1. List directories using ls and shell wildcard

    $ ls -d */
    dir1/	dir2/
    
  2. List using ls -l and egrep

    $ ls -l | egrep "^d"
    drwxrwxr-x  2 user1  staff  68 Feb 17 22:55 dir1
    drwxrwxr-x  2 user1  staff  68 Feb 17 22:55 dir2
    
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments