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

» Mirror Website Directory Over FTP

You can easily mirror the contents of a directory over FTP using the lftp program on Linux. To connect, create a configuration file for lftp that specifies the credentials for the ftp server, the directory on the remote ftp server that you want to download files from, and where you want to place them on the local machine:123456set ftp:anon-user "ftpusername"set ftp:anon-pass "ftppassword"set ftp:ssl-allow noopen remote-ftp-server.commirror -c /remote/directory/...

» Introduction to LaTeX

LaTeX is a self-described document preparation system that is often used for research papers or other technical publications.  It is, in essence, an extremely useful computer language that interprets code and produces a well-formatted document.  It can greatly increase productivity due to the ease of formatting, and other nicities like automatic figure and reference numbering and easy mathematical representation.  Unfortunately, it also have a very steep learning curve. ...

» How to Rename a File or Directory from a Linux Terminal

The easiest way to rename a file from a linux terminal is simply to move it to the same directory with a different name.mv original_name.txt new_name.txt The example above will rename original_name.txt to new_name.txt.  The same syntax will also work for a directory.