List Only Subdirectories for Shell Scripting

I like to have the following snippet in my .zshrc (or .bashrc) for convenience

alias lsd="ls -l|awk '/^d/ {print \$9}'"

It displays all subdirectories underneath the current directory. The goodness in this variant is that it gives you the pure names and that you can use it in loops without hassle :

for d in `lsd`; do
mv $d/resultfile.dat $d_result.dat;
rmdir $d;
done

Leave a Reply