How to Count the Number of Files in a Directory in Linux

(0 votes, average 0 out of 5)

Counting the number of files in a directory from a Linux command line is easy.  The following command will return the number of files in the current directory and all subdirectories:

 

$> find directory_name -type f -follow | wc -l

 

 

This will count all files and files in subdirectories, but not the subdirectories themselves.  To find all the files in only the current directory, you can use:

 

$> find directory_name -type f -maxdepth 1 -follow | wc -l

 

 

If you would like to count subdirectories, simply remove the -type flag.

Partner Links:
Last Updated on Tuesday, 05 October 2010 17:39  
Related Articles

» Access Windows Files From within a Ubuntu (Wubi) Install

So maybe you have just installed Ubuntu through the Wubi installation or have been using Ubuntu through Wubi for a while, but you find yourself trying to get access to your Window's documents/music/videos/etcetera from Ubuntu and your not sure where to look.  Well, the solution is pretty simple but not very intuitive for most users. Follow these instructions to get access to the files contained within your Windows installation:Assuming your using Ubuntu 10.xx, go to the top left:...

» How to connect an Apple Bluetooth Keyboard to Ubuntu (Troubleshooting)

Note: This guide uses programs specific to Ubuntu 10.04 (Lucid Lynx) and newer. For older versions of Ubuntu, please refer to .Sometimes the Ubuntu bluetooth stack can behave erratically and prevent you from connecting your Apple Bluetooth Keyboard (or other bluetooth device). The normal procedure for connecting your bluetooth keyboard involves the following steps:First, make sure the bluetooth applet is running by looking for the bluetooth icon on your panel:If it is not running, press ALT+F2,...

» Set the hardware clock on your computer from Linux

Rather than rebooting to set the hardware clock in the BIOS, you can sync the hardware clock on your machine to the current time in Linux using the hwclock and date commands.To set the hardware clock's date and time, use the hwclock command:hwclock --set --date "01/01/70 01:01:01" The date command allows you to get the current date, in the above format when using these arguments:date +'%m/%d/%y %H:%M:%S' Thus, you can combine the two commands to sync the hardware clock with the time in your...