[Linux] Linux commands for counting folders and files, and linux statistics

Source: Internet
Author: User

[Linux] Linux commands for counting folders and files, and linux statistics

# View the number of files in the current directory (excluding files in subdirectories)

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

# View the number of files in the current directory (including files in sub-Directories) Note: R, representing sub-Directories

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

# View the number of folders in the current directory (excluding the directories in the subdirectories). If you want to view the subdirectories, add the R

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

# Query the number of all files in the directory with the specified prefix name in the current path
# For example, count the total number of files in all directories starting with "20161124"

Ls-lR 20161124 */| grep "^-" | wc-l

 

Note the following for each command parameter:
Ls-l
This command outputs the information in the specified directory in a long list (the current directory is not specified), and R indicates the "file" in the subdirectory ", this "file" refers to the general term for directories, links, and device files.

Grep "^ d"Indicates the directory,"^ -"Indicates a file

Wc-l
Indicates the number of rows of output information. Because only common files are left after filtering, and a directory or file corresponds to a row, the number of rows of statistics is the number of directories or files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.