Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: listing/deleting empty directories recursively



Thor Andreassen wrote:
> > This should do the trick:
> >
> > for dir in `ls -ld **/*(/^F)`; do echo $dir > LOGFILE; rmdir $dir; done
>
> You should use double quotes (") around the dir variable if you have
> dirnames with spaces (and some other chars), i.e. echo "$dir" and rmdir
> "$dir".

That probably wouldn't work, since ls -ld prints a whole lot of additional 
information that will be interpreted as directories to log and delete. It's 
far simpler to do away with ls:

for dir in **/*(/^F); do print $dir >> LOGFILE; rmdir $dir; done

or with the alternative syntax I really like:

for dir (**/*(/^F)) { print $dir >> LOGFILE; rmdir $dir }

As far as I can see, filenames generated this way are already quoted 
correctly, so spaces and special characters shouldn't be an issue.

Christian



Messages sorted by: Reverse Date, Date, Thread, Author