Re: basic command pipe question



Steven W. Orr wrote:
On Sunday, Jun 18th 2006 at 14:14 -0700, quoth Don Russell:

=>I need some basic CLI help. :-) I've googled, and read, and I can't find how
=>to erase a bunch of files in one go.
=>
=>Specifically, I need a command that will erase *.zip files, regardless of the
=>text case of the .zip part....
=>
=>So far, I have
=> ls | grep -iE \\.zip$
=>
=>That gives me the correct list of files.... but I don't know how to get rm to
=>process that list.. It doesn't look like rm has an option to read the file
=>name from stdin, it's expecting the file name as a CLI argument.
=>
=>I know this is basic stuff.... I'm obviously missing some fundamental concept
=>of command line processing. :-)

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;


Always, wait, should I say that again in reverse, blinking underlined text?, *ALWAYS* use form 1.

If you don't understand it, read the man page. Use it. Love it.

Use of 1 will run one skinny process.

2. will execute a seperate process for *EACH* file to be deleted.

3. will execute a seperate process for *EACH* file to be deleted and would potentially overflow before the for loop even starts.

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.

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. If there are too many files, a buffer could overflow trying to hold the entire list of globbed file names.

So, the most robust solution seems to be using pipes and xarg, but WITH the --null option.... the downside being that it further complicates the pipe line.... How to add the terminating null to the strings coming out of grep?

Don

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: xp_cmdshell default path (system32) problem
    ... building a batch file in code and then ... it will NOT actually execute the delete if the patch I supply is not valid. ... I'm use xp_cmdShell to execute "erase" command like ...
    (microsoft.public.sqlserver.programming)
  • Re: Optimax
    ... Instead of calling 'system' to execute ... pipe and executes them. ... # Send the command to the background and wait for it to complete. ... # execution of the optimars under different os's. ...
    (rec.games.corewar)
  • Re: xp_cmdshell default path (system32) problem
    ... I'm use xp_cmdShell to execute "erase" command like commands to delete the files. ... I haven't executed the actual erase statements yet but rather have been running test where I just perform a DIR instead of a ERASE to confirm what WILL get deleted when I do it for real. ... The problem is, if the directory that I supply doesn't exist, then the command appears to opporate on the "default path". ... However, this doesn't protect me later when my script is running as a scheduled job and some unssuspecting sole happens to delete, rename or change the security settings on my directory and now the next time the job runs I crush SYSTEM32! ...
    (microsoft.public.sqlserver.programming)
  • Re: xp_cmdshell default path (system32) problem
    ... I'm use xp_cmdShell to execute "erase" command like commands to delete the files. ... I haven't executed the actual erase statements yet but rather have been running test where I just perform a DIR instead of a ERASE to confirm what WILL get deleted when I do it for real. ... The problem is, if the directory that I supply doesn't exist, then the command appears to opporate on the "default path". ... However, this doesn't protect me later when my script is running as a scheduled job and some unssuspecting sole happens to delete, rename or change the security settings on my directory and now the next time the job runs I crush SYSTEM32! ...
    (microsoft.public.sqlserver.programming)
  • Re: xp_cmdshell default path (system32) problem
    ... I'm use xp_cmdShell to execute "erase" command like ... I haven't executed the actual erase statements yet but rather have been ... my script is running as a scheduled job and some unssuspecting sole ...
    (microsoft.public.sqlserver.programming)