Re: basic command pipe question

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

 



Les Mikesell wrote:
On Sun, 2006-06-18 at 22:47, Don Russell wrote:

I see how
    ls | grep -i '\.zip$' | xargs rm
is the preferred method of the three above....

But... in reading the man pages for xargs, it says this may be problematic if the file name contain blanks.

If you don't mind directory recursion:

find -iname '*.zip' -print0 |xargs -0 rm


What's your opinion of
    rm *.[zZ][iI][pP]

Although, if I understand properly what's happening here, the pipe solution allows files to be erased as they are found in the filelist, while the gobbing method first requires that all files that match be found, then each command is executed one after another.

No, this is the most efficient if it fits the command line buffer.
The shell expands the file list and gives the expanded command
line to one invocation of rm.

Ah.... I see...

So the most *robust* would be:

ls -a | grep --null -iE \\.zip$ | xargs --null rm -f

That would erase all file ending with any .zip in any combination of upper and lower case characters, even if the file namehave any embedded spaces or other "special" characters.

Don


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux