How to Count Number of Files in a Directory in Linux

How do you know how many files are there is a directory.

In this quick tutorial you8217ll learn various ways to count the number of files in a directory in Linux.

The simplest and the most obvious option is to use the wc command for counting number of files.

The above command will count all the files and directories but not the hidden ones. You can use -A option with the ls command to list hidden files but leaving out . and .. directories.

If you only want to count number of files including hidden files in the current directory you can combine a few commands like this.

Let me explain what it does.

Basically you use ls to list display all the files and directories with added to directory names. You then use pipe redirection to parse this output to the grep command. The grep command only displays the lines that do not have at the end. The wc command then counts all such lines.


Read Full Post

News Link:
RSS Link:

Linux Chatter is a news aggregator service that curates some of the best Linux, Cloud, Technical Guides, Hardware and Security news. We display just enough content from the original post to spark your interest. If you like the topic, then click on the 'read full post' button to visit the author's website. Use Linux Chatter to find content from amazing authors!

Note: The content provided has been modified and is not displayed as intended by the author. Any trademarks, copyrights and rights remain with the source.

Disclaimer: Linux Chatter sources content from RSS feeds and personal content submissions. The views and opinions expressed in these articles are those of the authors and do not necessarily reflect those of Linux Chatter.