[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] THANKS to all who replied to "ls -rt | rm -i" problem, BUT...



Joe Knapka wrote:
> Geoffrey wrote:
>> Joe Knapka wrote:
>>
>>> Hi Courtney,
>>>
>>> This worked for me just now, to interactively
>>> remove files modified on March 15:
>>>
>>> rm -i $(ls -l | grep 'Mar 15' | cut -d ' ' -f 9)
>>
>> rm -i $(ls -l |awk '/Mar 15/ {print $NF}'
>>
>> Will save you a WHOLE pipe and a process!
> 
> Oh well. The machine will happily execute either one,
> and I doubt it will care ;-)   Plus, I don't know
> awk, so the latter part of your command is
> somewhat mysterious to me. Especially the part
> where you omit the trailing paren; why does
> that work?

Ooops, it doesn't.... :(

rm -i $(ls -l |awk '/Mar 15/ {print $NF}')

> 
>> Be aware that file names with spaces in them will screw up your efforts. :(
> 
> That's a serious issue, and an excellent reason
> to prefer your solution. I never put spaces in
> filenames, and usually if someone sends me a file
> with a space in the name, I write that person out
> of my will at once.

Actually, the awk solution won't work either, because NF is the number 
of fields and would simply pass the last field of the ls output.

This could be extended to handle this issue, but I'm too busy to deal 
with it right now. :(

-- 
Until later, Geoffrey