• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remove some files recursively

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic