Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: listing/deleting empty directories recursively
- X-seq: zsh-users 9698
 
- From: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
 
- To: zsh-users@xxxxxxxxxx
 
- Subject: Re: listing/deleting empty directories recursively
 
- Date: Sat, 19 Nov 2005 14:54:58 +0000
 
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
 
- References: <tfrtn1dt9nf26m1rka6b9kg3bmcoa2evs4@xxxxxxx> <20051119115653.GA329@xxxxxxxxxxxx> <20051119115926.GB329@xxxxxxxxxxxx> <200511191348.29062.cht@xxxxxxxxx>
 
- Sender: news <news@xxxxxxxxxxxxx>
 
* Christian Taylor (2005-11-19 12:48 +0100)
> 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
Exactly. Using "for x in $(ls)" or "for x in $(ls *)" instead of "for
dir in *" is a common mistake (mentioned in "From bash to zsh").
 
> 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.
Sorry, but it completely the other way round: the filenames are not
split (shwordsplit) so there's no need to quote them.
That's one major reason for the superiority of zsh to other shells
like bash.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author