How to display the number of Linux subfolders and files

  

Generally speaking, the number of subfolders and files in the system is very large, we can't count them one by one, but in Linux, we can Display the view by command.

Here's how:

find command to view (recommended):

all subdirectories number:

[root @ localhost ~] # find pma -type d |  Wc -l

125

[root@localhost ~]# find pma/-type d |  Wc -l

125

[root@localhost ~]# find pma/* -type d |  Wc -l

124 --correct

Reasons for different results:

[root@localhost ~]# find pma -type d |  More

pma -- the first line of output

[root@localhost ~]# find pma/* -type d |  More

pma/examples -- output first line

Summary: Use pma/* does not include the parent directory of pma, only the subdirectories under it.

Number of all files:

[root@localhost ~]# find pma -type f |  Wc -l

987

[root@localhost ~]# find pma/-type f |  Wc -l

987

[root@localhost ~]# find pma/* -type f |  Wc -l

987

tree command view (not recommended):

[root@localhost ~]# tree pma

……< Br>

124 directories, 984 files

---------------------------------- -------

[root@localhost ~]# tree pma/

……

124 directories, 984 files

Du command to view:

[root@localhost ~]# du -ah pma/* |  Wc -l

1111

Summary: The result of du view is 1111, the number of subdirectories is 124, and the number of files is: 1111-124=987, so the result of the tree command should be Inaccurate, as for which file is less calculated, this problem is not checked, it is recommended to use the find command to view.

The above are two ways to view the number of subfolders and files. As mentioned above, Xiaobian thinks that using the find command to display the view will be relatively accurate. If friends and friends have a more convenient way, welcome to interact with Xiaobian.

Copyright © Windows knowledge All Rights Reserved