![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
|
|
General Help All your general support questions for Ubuntu, Kubuntu, Edubuntu and Xubuntu. |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
First Cup of Ubuntu
![]() Join Date: Nov 2006
My beans are hidden!
|
Recursively remove files with wildcard
I've been searching for a way to do this extremely simple task but cannot seem to find one. What I want to do is remove all the files of a certain type (.class) recursively.
I tried this: Code:
rm -rv *.class I know that I can use a for loop to do it, but is there no simpler way? |
|
|
|
|
|
#2 |
|
I Ubuntu, Therefore, I Am
![]() Join Date: Jan 2006
Location: Leuven, Belgium
Beans: 3,414
|
Re: Recursively remove files with wildcard
That command should work.. I use wildcards like that all the time.
Are you sure you're in the right directory etc? Does rm output something? |
|
|
|
|
|
#3 |
|
First Cup of Ubuntu
![]() Join Date: Nov 2006
My beans are hidden!
|
Re: Recursively remove files with wildcard
That worked, thanks a lot.
Yes I am sure that I was in the same directory. It says that it cannot find the specified file. If you can get it to somehow work, could you post how you did it? |
|
|
|
|
|
#4 | ||
|
Gee! These Aren't Roasted!
![]() Join Date: Jan 2005
Location: Europe/France
Beans: 219
|
Re: Recursively remove files with wildcard
rm -r is for deleting directories recursively, this is not what you want to do
instead, you can use find, something like that (replace the path and the pattern) : first check : Quote:
Quote:
Last edited by souki; January 13th, 2007 at 01:34 PM.. |
||
|
|
|
|
|
#5 |
|
Gee! These Aren't Roasted!
![]() Join Date: Jan 2005
Location: Europe/France
Beans: 219
|
Re: Recursively remove files with wildcard
sorry, double post
|
|
|
|
|
|
#6 | ||
|
Gee! These Aren't Roasted!
![]() Join Date: Jan 2005
Location: Europe/France
Beans: 219
|
Re: Recursively remove files with wildcard
for your security, I have to tell you,
I'm sure that rm -r works only on directories if you don't believe me, check the manual or try this proof : Quote:
that's it, the pattern cannot be recursive all you can do is Quote:
please, always use the "find" method I mention earlier, it is safe |
||
|
|
|
|
|
#7 |
|
A Carafe of Ubuntu
![]() |
Re: Recursively remove files with wildcard
There is an easy explanation for that: All wildcards get expanded by the shell _before_ it gets passed to the program. Programs never see wildcards. So the shell expands *.class to 1.class 2.class in the current directory, and then passes these arguments to the program. So you just pass 2 "class" files to rm, and it just deletes that.
__________________
The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners. |
|
|
|
|
|
#8 |
|
I Ubuntu, Therefore, I Am
![]() Join Date: Jan 2006
Location: Leuven, Belgium
Beans: 3,414
|
Re: Recursively remove files with wildcard
Code:
ramses@icarus:~$ mkdir test ramses@icarus:~$ cd test/ ramses@icarus:~/test$ touch 1.class ramses@icarus:~/test$ touch 2.class ramses@icarus:~/test$ touch foo.class ramses@icarus:~/test$ touch test ramses@icarus:~/test$ ls 1.class 2.class foo.class test ramses@icarus:~/test$ rm *.class ramses@icarus:~/test$ ls test ramses@icarus:~/test$ |
|
|
|
|
|
#9 |
|
Gee! These Aren't Roasted!
![]() Join Date: Jan 2005
Location: Europe/France
Beans: 219
|
Re: Recursively remove files with wildcard
I don't think so, he's pretty clear with what he wants to do
"remove all *.class files recursively" |
|
|
|
|
|
#10 |
|
First Cup of Ubuntu
![]() Join Date: Apr 2007
Beans: 7
|
Re: Recursively remove files with wildcard
I wrote a howto for deleting files recursively (you may even preview which files will be deleted):
http://en.tuxero.com/2007/09/how-to-...-files-in.html Cheers! |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|