I am writing a script in bash on Linux and need to go through all subdirectory names in a given directory. How can I loop through these directories (and skip regular files)?
For example:
the given directory is /tmp/
it has the following subdirectories: /tmp/A, /tmp/B, /tmp/C
I want to retrieve A, B, C.
a minimal bash loop you can build off of (based off ghostdog74 answer)
to zip a whole bunch of files by directory
All answers so far use
find
, so here's one with just the shell. No need for external tools in your case:Works with directories which contains spaces
Inspired by Sorpigal
Original post (Does not work with spaces)
Inspired by Boldewyn: Example of loop with
find
command.