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

Re: deleting specific files



on Fri, Mar 23, 2001 at 12:53:59PM -0600, Jason P. Holland (jphollan@earthlink.net) wrote:

> > I need to delete a bunch of files, all of them of the form 
> > *.doc, scattered into several subdirectories inside a given
> > directory. What should I do?

> find /dir -name "*.doc" -exec rm -rf {} \;

As noted: wrong.

Several options:

  - Use an interactive delete.  I actually *don't* recommend this
    method, because it's easy to trip yourself up.  But, to demonstrate:

       $ find . -type f -name \*.doc -ok rm {} \;

  - Create a script.  This *is* my preferred method.

       $ find . -type f -name \*.doc | sed -e '/.*/s//rm &/' > rmscript
       # Edit the script to make sure it's got The Right Stuff
       $ vi rmscript
       # run it
       $ chmod +x rmscript; ./rmscript

   - Slight variation on above:  create a "script" using the vi shell
     editing features.  '^' indicates control-key (ctrl):

       $ set -o vi
       ^k^v  # you are now in a full-screen vi editor session
       # edit script to preferences, including piping in command ouptut.  
       # when done:
       <esc>:wq
       # script executes...and, no mess.  Nothing to clean up.

Cheers.

-- 
Karsten M. Self <kmself@ix.netcom.com>    http://kmself.home.netcom.com/
 What part of "Gestalt" don't you understand?       There is no K5 cabal
  http://gestalt-system.sourceforge.net/         http://www.kuro5hin.org

Attachment: pgp3obnCICKNy.pgp
Description: PGP signature


Reply to: