View the number of files in each subfolder of a specified folder in Linux

View the number of files in each subfolder of a specified folder in Linux

count script

#!/bin/sh
numOfArgs=$#
if [ $numOfArgs -ne 1 ]; then
  echo -e "Usage: \nbash $0 dirForCount"
  exit -1
fi
# args
ROOTDIR=$1
# core part
find $ROOTDIR -maxdepth 1 -type d | sort | while read dir; do
count=$(find "$dir" -type f | wc -l)
echo "$dir: $count"
done

implement

$ bash count.sh benchmark
benchmark: 2317
benchmark/0: 20
benchmark/1: 891
benchmark/2: 65
benchmark/3: 13
benchmark/4: 1328

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Linux shell command counts the value of a column after deduplication
  • Tips for viewing History records and adding timestamps in Linux
  • Several ways to run Python programs in the Linux background
  • Creating and executing Linux shell scripts
  • Python uses paramiko to operate Linux
  • Android's implementation method of executing shell scripts in the Linux terminal to directly print the log of the currently running app
  • How to remotely batch execute Linux command programs using pyqt
  • Use of Zabbix Api in Linux shell environment
  • How to recover accidentally deleted messages files in Linux
  • Shell command to realize the method of merging multiple files in the current directory into one file

<<:  mysql join query (left join, right join, inner join)

>>:  How to import js configuration file on Vue server

Recommend

Introduction to Nginx regular expression related parameters and rules

Preface Recently, I have been helping clients con...

Use PS to create an xhtml+css website homepage in two minutes

There are too many articles about xhtml+css websi...

npm Taobao mirror modification explanation

1. Top-level usage 1. Install cnpm npm i -g cnpm ...

Implementation of CSS scroll bar style settings

webkit scrollbar style reset 1. The scrollbar con...

JavaScript modularity explained

Table of contents Preface: 1. Concept 2. The bene...

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve The ...

Example of using MySQL to count the number of different values ​​in a column

Preface The requirement implemented in this artic...

Introduction to installing and configuring JDK under CentOS system

Table of contents Preface Check and uninstall Ope...

Exploring the practical value of the CSS property *-gradient

Let me first introduce an interesting property - ...

MySQL max_allowed_packet setting

max_allowed_packet is a parameter in MySQL that i...

CSS to achieve the effect of rotating flip card animation

The css animation of the rotating flip effect, th...

Do you know the meaning of special symbols in URL?

1.# # represents a location in a web page. The ch...

Implementation of nginx flow control and access control

nginx traffic control Rate-limiting is a very use...

Detailed explanation of the use of React list bar and shopping cart components

This article example shares the specific code of ...