Need help on Linux rm command

For system help, all hardware / software topics NOTE: use Coders Corner for all coders topics.

Moderators: Krom, Grendel

Post Reply
User avatar
Diedel
D2X Master
D2X Master
Posts: 5278
Joined: Thu Nov 05, 1998 12:01 pm
Contact:

Need help on Linux rm command

Post by Diedel »

I want to recursively delete all files ending with '~', starting in a folder named './src'. I tried 'rm -r src/*~', but this only deleted the targetted files in ./src, not in the sub folders of ./src. :?
Cuda68
DBB Captain
DBB Captain
Posts: 745
Joined: Mon Jul 09, 2001 2:01 am
Location: Denver, CO USA
Contact:

Re: Need help on Linux rm command

Post by Cuda68 »

Diedel wrote:I want to recursively delete all files ending with '~', starting in a folder named './src'. I tried 'rm -r src/*~', but this only deleted the targetted files in ./src, not in the sub folders of ./src. :?
I think it should have been " rm -r ./src/*~ " but you can also use the -v for verbose and it will spell what it is doing and when.

OPTIONS
Remove (unlink) the FILE(s).

-d, --directory
unlink FILE, even if it is a non-empty directory (super-user
only)

-f, --force
ignore nonexistent files, never prompt

-i, --interactive
prompt before any removal

-r, -R, --recursive
remove the contents of directories recursively

-v, --verbose
explain what is being done
User avatar
Diedel
D2X Master
D2X Master
Posts: 5278
Joined: Thu Nov 05, 1998 12:01 pm
Contact:

Post by Diedel »

Cuda,

don't you think I have read the manual? I have read it like three times. And can't you read? I have used '-r', but it doesn't work.
User avatar
roid
DBB Master
DBB Master
Posts: 9996
Joined: Sun Dec 09, 2001 3:01 am
Location: Brisbane, Australia
Contact:

Post by roid »

moved to tech forum
while drinking
i rock
so does my cat
User avatar
roid
DBB Master
DBB Master
Posts: 9996
Joined: Sun Dec 09, 2001 3:01 am
Location: Brisbane, Australia
Contact:

Post by roid »

personally i don't have much EXP points in Linux, but
can't you:
- first temporarily move (to somewhere secure) all of the directorys you don't want to delete files from? (perhaps using a visual file manager that can sort things alphabetically and select directorys with a drag-box)
- run this from the original directory 'rm -r *~'
- then move those other folders back
User avatar
KompresZor
DBB Captain
DBB Captain
Posts: 919
Joined: Wed Jul 31, 2002 2:01 am
Location: Clearfield, Pennslyvania

Post by KompresZor »

First, the test...

Code: Select all

locate *.~¦grep /path/to/scr
make sure these are the right files

then....

Code: Select all

rm 'locate *.~¦grep /path/to/scr'
to remove the files

rm -r is to remove a directory with files in it since \"rmdir\" will not unlink a directory unless it is empty.
:)
Cuda68
DBB Captain
DBB Captain
Posts: 745
Joined: Mon Jul 09, 2001 2:01 am
Location: Denver, CO USA
Contact:

Post by Cuda68 »

Ya know what - skip it, you missed my point totally.
User avatar
FunkyStickman
DBB Ace
DBB Ace
Posts: 309
Joined: Wed Apr 20, 2005 2:26 pm
Location: 'Nawlins

Post by FunkyStickman »

If you use rm -rf ./*~ it should do the trick. When deleting recursively, you have to use the \"-force\" option for it to work sometimes.
User avatar
Zantor
DBB Ace
DBB Ace
Posts: 453
Joined: Sat May 28, 2005 2:43 pm
Location: Midwest United States
Contact:

Re: Need help on Linux rm command

Post by Zantor »

Diedel wrote:I want to recursively delete all files ending with '~', starting in a folder named './src'. I tried 'rm -r src/*~', but this only deleted the targetted files in ./src, not in the sub folders of ./src. :?
Try doing "rm -r ./src" I don't know if that may work.
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy »

Well seeing as you're oh so knowledgable in the world of Linux, having read the manpage for rm three times, you'd obviously know that wildcard expansion is done by the shell, not the command it is passed to. And therefore, \"./src/*~\" expands to every filename in ./src that ends with ~. But like I said, being the absolute fscking genius you are you obviously knew that already.

[spoiler]`rm ./src/*~ ./src/*/*~` you tool.[/spoiler]
Post Reply