w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Enter a child directory and list its subdirectories in bash script

Check if following helps:

find ~/lab2/students -type d -maxdepth 1

And in case you want the directory(students name) names only:

find ~/lab2/students -maxdepth 1 -type d  | awk -F/ '{print

Please read man page of find, it will help a lot.

awk -F/ '{print $NF}' is filtering the last field.

And in case you want to something with those directory names in your bash script you can do something like:


for file in $(find ~/lab2/students -maxdepth 1 -type d) #or you can use the
awk one here

echo $file
#your stuff here


© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.