This bash script calculates the total number of directories including the sub-directories in the current directory but does not count the current directory. Before I proceed to the bash scripting let me explain the bash script.
What is Bash Script?
What is a shebang?
Shebang is a character sequence consisting of characters, starting with a sharp sign and an exclamation mark (#!) at the beginning of the bash script. Shebang can also be called sharp exclamation, sha-bang, or hashbang. Shebang is the combination of bash (#) and bang (!) follow by the bash shell path. Shebang is a path to the bash interpreter, that tells the shell to execute it via the bash shell.
Below is an example of a shebang statement;
#! /bin/bash
In order to get a total number of directories in Linux, we will need to make use of two different Linux commands. first will have to execute and afterward pass its outcome as the input for the second command.
first_command | second_command
find -type d
find -mindepth 1
find -mindepth 1 -type d
wc -l
find -mindepth 1 -type d | wc -l