Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does linux count the number of files

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about how linux counts files. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Linux counts the number of files: 1. Check the number of files under the path, code is [ls-l | grep "^ -" | wc-l]; 2, check the number of folders under the path, code is [ls-l | grep "^ d" | wc-l].

Linux counts the number of files:

For linux end-users, counting the number of files under the folder is a frequent operation, but there are no commands that can be used directly, but it is simple to use pipe commands and regularization, and it is not difficult to understand how to count the number of files under the folder under linux.

The command ls-l outputs information about files and directories

It is not difficult to see that if it is a file, the first character of the string information of the line is "-". If it is a directory, the first character of the line is "d", which means directory, find the difference between the two, and run a command that can distinguish the first character.

So

1. If you want to see the number of files under the path, you can use the following instruction

Ls-l | grep "^ -" | wc-l

two。 If you want to see the number of folders under the path, you can use the instruction

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

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

Ls-lR | grep "^ -" | wc-l Thank you for reading! About linux how to count the number of files to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report