aspose file tools*
The moose likes Linux / UNIX and the fly likes Remove some files recursively Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Remove some files recursively" Watch "Remove some files recursively" New topic
Author

Remove some files recursively

Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
I have a directory ../classes under which i have a lot of subdirectories
../classes/com/financial/argon
../classes/com/financial/argon/util
../classes/com/orion/util
...............
............
All these directories contains java & class files now i want to remove all the java files which is any where in this directory structure by giving a command from ../classes
I tried as follows rm -Rf *.java & rm -rf *.java but it doesn't work

I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
Ryan Senior
Greenhorn

Joined: Jul 14, 2001
Posts: 12
If you would like to delete a directory and all of it's subdirectories, type rm -rf <directory>
so if i wanted to delete my entire usr directory, I would type
rm -rf /usr
be careful, this isn't windows, if you type rm -rf /, it will delete everything without warning because -f means force (no matter what)
post another message if that doesn't do the trick
Amol Dharmadhikari
Greenhorn

Joined: Jul 18, 2001
Posts: 10
Anoop,
I dont know whether it can be done by a single unix command. But the alternative is to write a simple shell/PERL script which takes the directory name, goes through all the files/directories which lie below it, and delete those having extention '.java'
Amol
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

find . -name "*.java" -print0 | xargs -0r rm -f
The "find" command is a treasure too little known. I got the above text by doing "info find", selecting "common tasks" then "cleaning up". Actually, I think I have been getting away with a shorter version:
find . -name "*.java" | xargs rm -f
But I'd test that someplace harmless, first.


Customer surveys are for companies who didn't pay proper attention to begin with.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I use ant build in task "Delete" to do the same, and it is platform independent.

However, Tim's way works great!!! Learn something new everyday. Thanks a lot!

SCJD Study Group has been moved to http://www.developergroup.org/
[This message has been edited by Roseanne Zhang (edited September 29, 2001).]
Eric Handbury
Greenhorn

Joined: Sep 23, 2001
Posts: 8
I wrote a java program that recursively goes through sub-directories deleting files of a user-defined suffix. I use it to clear out old .class files. I can send it to you if you post your e-mail address.
Eric.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remove some files recursively