The following command will print the number of files in the current directory:
ls | wc -l
The ‘ls’ command prints the directory listing. The output of ls is piped into the wc command by the inclusion of the ‘|’. Finally, the ‘wc’ command performs a word count on the directory listing it was given, and because ls outputs each filename as a word, you get the number of files in the directory.
Linux: count number of files in a directory
Next post: 100 Free High-Quality XHTML/CSS Templates
Sign up for our daily email newsletter:
You must log in to post a comment.