basic command pipe question
Keith G. Robertson-Turner
fedora-gmane.00002 at genesis-x.nildram.co.uk
Mon Jun 19 03:20:37 UTC 2006
Todd Zullinger wrote:
> Sam Varshavchik wrote:
>> WTF????????
>>
>> Is everyone on drugs, here?
> In the current political climate I feel it's best to refrain from
> answering that. (Insert dope-smoking smiley here. :)
>> Or did:
>>
>> rm -f *.zip
>>
>> suddenly stop working, for some stupid reason?
> I believe the wrinkle the OP had was trying to match case
> insensitively. The simplest method for that is
>
> rm -f *.[Zz][Ii][Pp]
>
> Which has already been posted.
>
> Other than that, the other methods are just good ways to illustrate
> how many ways you can chain together commands. It's just a fun
> exercise. :)
Here's another, that ensures the file has both the right extension *and*
content:
rm \
`find . -name "*.[Zz][Ii][Pp]" | \
file -f - | \
grep "Zip archive" | \
sed -e "s/: .*//"`
(force switch omitted)
So this will not delete zip compressed "xpi" files, nor extensionless
zip files, nor non-zip files with (for whatever reason) zip extensions.
To catch all zip files regardless of extension (or lack thereof) you
would simply omit the "-name" argument to "find".
--
K.
More information about the users
mailing list