[SWLUG] shell script help

Dick Porter dick at acm.org
Sun Oct 20 23:05:05 UTC 2002


On Sun, 2002-10-20 at 23:18, bascule wrote:
> i need to enter each subdirectory of a higher level directory, perform the 
> same command and then back out and in to any other sub directories
> is using:
> 
> for i in`ls -R`;
> 	do yadayada;
> done

find . -type d -maxdepth 1 -exec sh -c "cd {}; yadayadayada" \;

The "-maxdepth 1" stops it recursing into subdirs of the subdirs.  The
"-exec blah blah" has to be terminated with "\;".  Using xargs(1)
instead of the "-exec" is usually cleaner, but it's complicated by
having to cd into the directory.

- Dick






More information about the Swlug mailing list