#!/bin/bash ## by Eugene Reimer 2008-11: ## USAGE EXAMPLE: ## for DIR in $(find-dirs) ;do ... done ##for each subdir... ## for DIR in $(find-dirs) . ;do ... done ##for each dir including this one... ## Typically used in scripts, where you'll sometimes want CURDIR to be included in the result, sometimes not. ## This script does NOT include it. Rationale: adding a "." is very easily done for when it's wanted, whereas other-way-round would be considerably more hassle. find -type d |sort | ##create the list of dirs, ordered sed '/^\.$/d; s|^\./||g' | ##eliminate line containing just dot, remove leading dot+slash, to simplify output tr '\n' ' ' |sed 's| $|\n|' ##newline->space, then revise ending space back to newline (together exactly what nl2sp does) exit Note: the newline-to-space translation isn't needed for such list-of-filenames to work in a bash for-statement, it does however make the result more people-readable; it may also make the result useful in a wider variety of contexts, although I'm far from sure about that; one counter-example involves using such a list as input to my SetIntersection, SetUnion, etc, scripts, as those require one-name-per-line format. When working with set-like lists or list-representation sets the need to convert between one-per-line and space-separated forms comes up so often that it begs for a pair of one-liner scripts to do those conversions. I have created those little scripts: nl2sp sp2nl; 2010-11-07: instead of adding a newline, now revises the ending space to newline, to produce a canonic space-separated list, as in nl2sp;