recursively removing only selected files

recursively removing only selected files

Post by red_cash.. » Sun, 14 Jan 2001 01:39:42



Hi, could anyone tell me how to recursively remove selected files in a
directory?  If I have a directory called dir, and I want to remove
all .o files in that directory how might this be done?  The closest I
could find on a manpage was using the -i option to select which to
delete, but I would rather not do it this way for fear of user error.
Thanks alot.

Sent via Deja.com
http://www.deja.com/

 
 
 

recursively removing only selected files

Post by John Gord » Sun, 14 Jan 2001 02:10:29



> Hi, could anyone tell me how to recursively remove selected files in a
> directory?  If I have a directory called dir, and I want to remove
> all .o files in that directory how might this be done?  The closest I
> could find on a manpage was using the -i option to select which to
> delete, but I would rather not do it this way for fear of user error.
> Thanks alot.

  cd dir
  find . -name "*.o" -type f | xargs rm

or, to be safe:

  cd dir
  find . -name "*.o" -type f > list.of.files
  vi list.of.files     (make sure you're not deleting anything important)
  cat list.of.files | xargs rm     (UUOC, i know)

---
"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang, rec.games.board



 
 
 

recursively removing only selected files

Post by Kurt J. Lanz » Sun, 14 Jan 2001 03:14:45



> Hi, could anyone tell me how to recursively remove selected files in a
> directory?  If I have a directory called dir, and I want to remove
> all .o files in that directory how might this be done?  The closest I
> could find on a manpage was using the -i option to select which to
> delete, but I would rather not do it this way for fear of user error.
> Thanks alot.

Err... You must have mistyped your question. To remove
all .o files in a directory, why not:

        rm *.o

If, OTOH, you really want recursion to subdirectories,
why not:

        find dir -name "*.o" -exec rm \{} \;

If your don't know about find, it's time to read a few
man pages.

 
 
 

1. recursively removing only selected files

Hi, could anyone tell me how to recursively remove selected files in a
directory?  If I have a directory called dir, and I want to remove
all .o files in that directory how might this be done?  The closest I
could find on a manpage was using the -i option to select which to
delete, but I would rather not do it this way for fear of user error.
Thanks alot.

Sent via Deja.com
http://www.deja.com/

2. Find the name of package which owned a file.

3. recursively deleting selected files

4. Differences in SunOS ans Solaris?

5. Can I recursively remove files ??

6. Advocating

7. Recursively remove files

8. A question about PINE

9. How do you remove selected lines from file?

10. Removing funny files (Re: how do i remove a file with a ~ in it ????)

11. Can't remove a file called "---remove-files"

12. How to remove a dir recursively?