Use ls to find only files or only directories

Last modified: 
Wednesday, January 27th, 2016
Topics: 
file system

How find only files (or only directories) with ls in the linuxes.

Files only

ls -l | grep "^-"
-rw-r--r--@  1 eriks  wheel  1430 May  1  2015 Config.js
-rw-r--r--@  1 me  us  5768 Jan  1  1970 Gruntfile.js
-rw-r--r--@  1 me  us  1215 Jan  1  1970 README.md
-rw-r--r--@  1 me  us  3925 Jan  1  1970 devel.html
-rw-r--r--   1 me  us  1414 Jan 25 14:50 index.html
-rw-r--r--@  1 me  us   267 Jan  1  1970 package.json
-rw-r--r--@  1 me  us  4088 Jan  1  1970 tour.xml

Directories only

ls -l | grep "^d"
drwxr-xr-x@  4 me  us   136 Jan 26 14:58 css
drwxr-xr-x@  7 me  us   238 Apr  2  2015 dist
drwxr-xr-x@ 30 me  us  1020 May 14  2015 images
drwxr-xr-x@  6 me  us   204 Jan 25 13:46 js
drwxr-xr-x   7 me  us   238 Apr  2  2015 node_modules
drwxr-xr-x@ 21 me  us   714 Jan 27 11:48 templates
drwxr-xr-x@ 13 me  us   442 Apr  2  2015 vendor


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.