Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Remove some files recursively

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 22520
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Why is the word "abbreviation" so long? And this ad is so short?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic