How to count the number of files in Linux

coldplay.xixi
Release: 2020-12-15 15:19:53
Original
7890 people have browsed it

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].

How to count the number of files in Linux

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

How to count the number of files in Linux

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
Copy after login

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
Copy after login

3. Count the number of files in a folder, including

  ls - lR|grep "^-"|wc -l
Copy after login
in 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template