Can U pipe filenames to rm???

Jeff Beadles jeff at onion.pdx.com
Sat Oct 6 13:49:22 AEST 1990


In <28790001 at col.hp.com> greiner at col.hp.com (Mike Greiner) writes:

>                    Piping filenames to the rm command???

>I am trying to write a script to uninstall files installed via an
>ninstall package.  I can generate a list of filenames to delete, but
>I haven't figured out how to pipe this list of names to rm.  Here's
>the heart of my script so far, followed by its output:

>    ninstall -h $1 -vvvvv -p $2 | grep path | cut -d " " -f4

>Now I want to pipe the output of this command into rm.  Here's the output:

>     /usr/local/doc/ninstall/UserGuide.mm
>     /usr/local/man/man1/ninstall.1
>     /usr/local/man/man1m/installd.1m

>There may be a pretty simple solution to this, but I haven't found it.  I'm
>considering using a for-loop that parses each line as the loop counter, 
>but don't know if that's the best approach...appreciate any suggestions!

Well, a couple simple ways that will work most everywhere...

 1)  rm -f `ninstall -h $1 -vvvvv -p $2 | grep path | cut -d " " -f4`

 2)  ninstall -h $1 -vvvvv -p $2 | grep path | cut -d " " -f4 | sh rm -f

 3)  ninstall -h $1 -vvvvv -p $2 | grep path | cut -d " " -f4 | xargs rm -f

 4)  ninstall -h $1 -vvvvv -p $2 | grep path | cut -d " " -f4 | while read file
     ; do ; rm -f $file ; done


There are pitfalls with all.
	#1, #2, and #3 will all complain if there are no files to remove
	  if you don't use the "-f" flag.
	#1 will fail if there are too many files to delete, or the total size
	  of their pathnames is above a magic number.
	#3 requires xargs
	#2 and #4 are bourne shell specific.


Have fun!
	-Jeff
-- 
Jeff Beadles	jeff at onion.pdx.com



More information about the Comp.unix.shell mailing list