how.wtf

Count number of files in Linux

· Thomas Taylor

Counting the number of files in Linux is made possible using the wc command!

Count number of files and directories in current directory

Using wc in combination with ls, the number of files and directories in the current directory can be displayed:

1ls | wc -l

Output:

1~/how.wtf/content/post$ ls | wc -l
2120

To include hidden files and directories, use the -A ls option.

1ls -A | wc -l

Count number of files in current directory

Using find and wc, the number of files in the current directory can be displayed:

1find . -maxdepth 1 -type f | wc -l

-maxdepth ensures that subdirectories are not counted.

Count number of files in current directory and subdirectories

Using find and wc, the number of files excluding directories can be displayed:

1find . -type f | wc -l

#linux  

Reply to this post by email ↪