How to count the number of specified types of files on a Linux terminal

Source: Internet
Author: User
Tags regular expression

Let's take a look at the technique of using the ls,grep and WC commands to count the number of files of a specified type in a directory. The interaction between commands is done through named pipes.

grep– a command that a user searches based on a given pattern or regular expression.

wc– commands for counting lines, words, and characters.

Statistics of the number of ordinary documents

In Linux, common files are represented by symbols.

The code is as follows:

Tecmint@tecmint ~/linux-tricks $ ls-l | grep ^-| Wc-l

7

Number of statistics catalogs

In Linux, the directory is represented by the symbol D.

The code is as follows:

Tecmint@tecmint ~/linux-tricks $ ls-l | grep ^d | Wc-l

1

Count the number of symbolic links and hard links

In Linux, symbolic links and hard links are represented by symbol L.

The code is as follows:

Tecmint@tecmint ~/linux-tricks $ ls-l | grep ^l | Wc-l

0

Count the number of block files and character files

In Linux, blocks and character files are represented by symbols B and C.

The code is as follows:

Tecmint@tecmint ~/linux-tricks $ ls-l/dev | grep ^b | Wc-l

37

The code is as follows:

Tecmint@tecmint ~/linux-tricks $ ls-l/dev | grep ^c | Wc-l

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.