
Often you may want to know the number of files, directories, and specific file types. It is really easy to find that using simple linux/unix commands on a terminal in Mac and Linux. The three linux commands the comes handy in counting the files/dirs are
- ls: The command “ls” lists the files
- wc: The command “wc” counts the number of lines or words
- grep: The command “grep” finds the pattern that we want to search
Combining these three commands with the optional arguments we can count on a terminal in Mac or Linux.
How to find the number of files in a directory?
ls -l | grep ^- | wc -l
How to find the number of sub-directories?
ls -l | grep ^d | wc -l
How to find the number of pdf files?
ls -l | grep pdf* | wc -l
Similarly to count other file types, like jpg, txt, and png, in a directory, we simply replace “pdf” in the above command with the file type that we are interested in.
Related posts:
- Useful Mac OS X/Linux Tips – Part 1
- Google Voice and Video Chat Finally Comes to Linux
- Five Gmail Tips To Deal With Attachments
- Google Chrome Evolves to Become Faster and Stable in Mac and Linux
- Google Services Get Command Line Utility, GoogleCL
- How to Find MAC Address/Physical Address on Windows, Kindle, and iPad
- iPhone 4 Tips and FAQs : Folders and the Total Number of Apps in iPhone 4