bash - How to loop over directories in Linux? -
i writing script in bash on linux , need go through subdirectory names in given directory. how can loop through these directories (and skip regular files)?
for example:
 given directory /tmp/
 has following subdirectories: /tmp/a, /tmp/b, /tmp/c
i want retrieve a, b, c.
cd /tmp find . -maxdepth 1 -mindepth 1 -type d -printf '%f\n'   a short explanation: find finds files (quite obviously)
. current directory, after cd it's
/tmp(imho more flexible having/tmpdirectly in find command. have 1 place,cd, change, if want more actions take place in folder)-maxdepth 1,-mindepth 1make sure,findreally, looks in current dir , doesn't include '.' in result-type dlooks directories-printf '%f\nprints found folder's name (plus newline) each hit.
e voila!
Comments
Post a Comment