Open In App

Shell Script to list the Number of Entries Present in Each Subdirectory Mentioned in the Path

In this article, we will discuss how to write a shell script to list the Number of Entries Present in Each Subdirectory Mentioned in the Path

Examples:



Directory: GeeksforGeeks
Subdirectories: GeeksforGeeks/Subdirectory1, GeeksforGeeks/Subdirectory2
Entries in Subdirectory1: gfg.txt, temp.sh
Entries in Subdirectory2: foo.txt, script.sh, pro.exe

Output: ./ Subdirectory1:    2
        ./ Subdirectory2:    3

Script:

# Shell script to count number of entries



# present in subdirectories of a path

# !/bin/sh

find . -maxdepth 1 -type d | while read -r dir

do printf “%s:\t” “$dir”; find “$dir” -type f | wc -l; done

Output:

Explanation:

Each of the lines of this script has been explained below in detail:

Article Tags :