Saturday, April 20, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 684  / 2 Years ago, wed, august 3, 2022, 12:23:20

The task is: Output when running the file will be the number of subdirectories (counting all subdirectories in the tree) in the entered directory.


I know how to recursive a dir using -r but how can i count all these number in a shell script file?


More From » scripts

 Answers
5

Try running ls -l -R | grep -c ^d in your terminal from the directory you want to know how many are inside of.


*** edit ***
Use the below to scan with a variable path prompted to the user.


#!/bin/bash
echo "Please enter path to scan:"
read path
ls -l -R $path | grep -c ^d

[#1236] Thursday, August 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
disdry

Total Points: 133
Total Questions: 128
Total Answers: 109

Location: Greenland
Member since Fri, Jul 31, 2020
4 Years ago
disdry questions
Tue, Apr 11, 23, 11:37, 1 Year ago
Thu, Oct 13, 22, 19:09, 2 Years ago
Fri, Oct 28, 22, 15:06, 2 Years ago
Sat, Feb 25, 23, 11:33, 1 Year ago
;