Linux LS lists the number of files in the directory

Source: Internet
Author: User

View the count of files in the current directory, including subdirectories.

ls-lr| grep "^-" | wc-l[Drink Small wine net pick]http://blog.hehehehehe.cn/a/12311.htm

Under Linux see a directory of files, or folders in the number of 3 commands: LS column directory, with grep, and then use the WC statistics.
To illustrate:
1. View the number of files in the current directory

Ls-l | grep "^-" | Wc-l

2, check the statistics of the current directory of the number of files, including sub-directories.

ls-lr| grep "^-" | Wc-l

3. See the number of folders (directories) in a directory, including subdirectories.

ls-lr| grep "^d" | Wc-l


Command explanation:
Ls-l

Long list output file information in this directory (note that the file here, different from the general file, may be a directory, links, device files, etc.), each line corresponding to a file or directory, if you want to list all subdirectories of the file is LS-LR.

grep "^-"

Here, the long list output information is filtered in part, only the general file, if only the directory is grep "^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.

Linux LS lists the number of files in the directory

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.