Re: basic command pipe question

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

 



Steven W. Orr wrote:

> You have gotten three different suggestions so far.
> 
> 1. Use xargs
> 
> ls | grep -i '\.zip$' | xargs rm
> 
> 2. Use find with -exec
> 
> find . -iname \*.zip -exec 'rm {]' \;
> 
> 3. Use process substitution.
> 
> for i in $(find -iname "*.zip"); do rm  $i; done;
> 

I'd add a variant of 2:

4. Use find to write a script

find . -iname \*.zip -printf "rm \"%p\"\n"

this will output a script with a rm command for each file to be deleted.
You can easily check the files that will be deleted (which is good,
because errors involving wildcards can be dangerous) and if all is OK,
you just rerun the command in this way

find . -iname \*.zip -printf "rm \"%p\"\n"|sh

If instead of rm you want to do something more complicated this
printf trick is quite useful.
Moreover, creative addons may be:
- |wc -l         to count how many file are affected
- |split -l 1000 to have many scripts which can be run in parallel
...

Another tip: if rm asks you confirmation because is aliased to "rm -i",
you can just use /bin/rm.

Best regards.
-- 
   Roberto Ragusa    mail at robertoragusa.it

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux