Linux statistics the number of files and folders under a folder

Source: Internet
Author: User

Count the number of files in a folder
Ls-l |grep "^-" |wc-l

Count the number of directories under a folder
Ls-l |grep "^d" |wc-l

The number of files under the statistics folder, including subfolders
Ls-lr|grep "^-" |wc-l

All JS files in the Statistics/home/han directory (including subdirectories) are:
Ls-lr/home/han|grep js|wc-l or Ls-l "/home/han" |grep "JS" |wc-l

The number of directories under the statistics folder, including the sub-folders
Ls-lr|grep "^d" |wc-l
Description
Ls-lr
Long list output file information in this directory (R for subdirectories note the files here, different from the general files, may be directories, links, device files, etc.)

grep "^-"
In this case, the long list output information is filtered, only the general files are preserved, if only the directory is ^d

Wc-l
Statistics output information of the number of rows, because it has been filtered to only the general file, so the statistical results are general file information line number, and because one line of information corresponding to a file, so that is the number of files.

======================================

If you view only folders
Ls-d can only display one.
Find-typed can see sub-folders
Ls-lf |grep/or ls-l |grep ' ^d ' only look at folders under current directory, not including down folders

Linux statistics the number of files and folders under a folder

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.