Skip to Content

Linux File Count in Directory (and subdirectory) - with Command Line

  • warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'stumble_go' was given in /home1/extraris/public_html/neohide/includes/menu.inc on line 348.
  • warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, '_translation_tab_access' was given in /home1/extraris/public_html/neohide/includes/menu.inc on line 452.

Linux Penguin

Today, I am back to give you a quick tip on how to count the Total Number of Files in a Directory (as well as sub-directories underneath it).

(Learn how to do it in Linux, using Command Line...)

Very simply, I am going to split into 2 parts. Firstly, to count the number of files in a particular directory. Secondly to count the total number of files in a directory and including all the sub-directories underneath it, using Linux command line.

Part 1: File Count in a Directory

Type the following in the command line:

 ls | wc -l

In the above command, you may need to deduct 2, because of the "." and ".." that are included in the count. But naturally, that gives you what you need.

Part 2: File Count in a Directory and Sub-directory

This is probably more useful, if you want to know the total number of files underneath the root.

find . type -f | wc -l

Very short command line, but it gives you the icing.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options