Thursday, April 25, 2013

List only directories or files in a Linux/Unix directory

To list just directories, use this command:

ls -l | egrep '^d'

If you just want the directories name without detail, then use this command:

ls -l | egrep '^d' | awk '{print $NF}'



To list just files, use this command:

ls -l | egrep -v '^d'

If you just want the file names without detail, then use this command:

ls -l | egrep -v '^d' | awk '{print $NF}'