Page 1 of 1

Need help on Linux rm command

Posted: Fri Feb 24, 2006 6:36 am
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. :?

Re: Need help on Linux rm command

Posted: Fri Feb 24, 2006 6:43 am
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

Posted: Fri Feb 24, 2006 6:55 am
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.

Posted: Fri Feb 24, 2006 7:01 am
by roid
moved to tech forum
while drinking
i rock
so does my cat

Posted: Fri Feb 24, 2006 7:53 am
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

Posted: Fri Feb 24, 2006 12:15 pm
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.
:)

Posted: Fri Feb 24, 2006 8:11 pm
by Cuda68
Ya know what - skip it, you missed my point totally.

Posted: Sat Feb 25, 2006 11:37 am
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.

Re: Need help on Linux rm command

Posted: Sun Feb 26, 2006 11:51 am
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.

Posted: Sun Feb 26, 2006 6:30 pm
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]