The number of statistical files under Linux

1. For linux end users, counting the number of files in a folder is a frequent operation, but there is no command that can be used directly, but it is easy to understand how to count linux by using pipeline commands and regularization. The number of files in the next folder

Command ls -l output file information and directory information

 

 

It is not difficult to see that if it is a file, the first character of the string information of the line displays "-", if it is a directory, the first character of the line displays "d", which means directory , Find the difference between the two, run the command that can identify the first character

 

and so

1. If you want to view the number of files in 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, you can use the command

  ls -l |grep "^d"|wc -l

3. Count the number of files in the folder, including those in subfolders

  ls - lR|grep "^-"|wc -l 

Guess you like

Origin www.cnblogs.com/sucretan2010/p/12689896.html