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