Home > Article > Operation and Maintenance > How to count the number of files in Linux
How to count the number of files in Linux: 1. Check the number of files under the path, the code is [ls -l |grep "^-"|wc -l]; 2. Check the number of folders under the path number, the code is [ls -l |grep "^d"|wc -l].
The operating environment of this tutorial: windows7 system, linux7.3 version. This method is suitable for all brands of computers.
Recommended: linux video tutorial
How to count the number of files in Linux:
For Linux terminal users, Counting the number of files in a folder is a common operation, but there is no command that can be used directly. However, it is simple to use pipeline commands and regularization. It is not difficult to understand how to count the number of files in a folder under Linux
The file information and directory information output by the command ls -l
It is not difficult to see that if it is a file, the string information of the line is One character is displayed as "-". If it is a directory, the first character displayed in the line is "d", which means directory. Find the difference between the two and run to identify the first character. The command
So
1. If you want to check the number of files under the path, you can use the following command
ls -l |grep "^-"|wc -l
2. If you want to check the number of folders under the path Number, you can use the command
ls -l |grep "^d"|wc -l
3. Count the number of files in a folder, including
ls - lR|grep "^-"|wc -lin subfolders.
The above is the detailed content of How to count the number of files in Linux. For more information, please follow other related articles on the PHP Chinese website!