Linux statistics the number of files under the current folder, the number of directories _linux shell

Source: Internet
Author: User

1) Statistics the number of files under the current folder

Copy Code code as follows:

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

2) Statistics the number of directories under the current folder

Copy Code code as follows:

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


3 Statistics The number of files under the current folder, including subfolders
Copy Code code as follows:

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


4 Statistics folder under the number of directories, including subfolders in the

Copy Code code as follows:

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


Description
Copy Code code as follows:

Ls-l

Long list output file information in the current folder (note the file here, different from the general file, may be directories, links, device files, etc.)
Copy Code code as follows:

grep "^-"

Here the long list output information filter part, only the general file, if only keep the directory is ^d
Copy Code code as follows:

Wc-l

Statistics output The number of rows, because has been filtered only general file, so the statistical result is the number of general file information, and because a line of information corresponding to a file, so that is the number of files.

Related Article

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.