tags:

views:

236

answers:

4

I tested:

rm \-\-remove-files

but I am unable to remove it. How can I do it?

+4  A: 

rm -- --remove-files

Joe
Alternative: rm ./--remove-files
lothar
The double quotes are unnecessary.
camh
Agreed. Not sure why I typed them!
Joe
+4  A: 
$ ls -lah -- --remove-files 
-rw-r--r--  1 xistence  xistence     0B May  4 19:29 --remove-files
$ rm -- --remove-files 
$ ls -lah -- --remove-files 
ls: --remove-files: No such file or directory

So what you want is to use the -- as one of the arguments to rm, that means it stops processing getopt's, after that anything is taken literally:

rm -- --remove-files
X-Istence
+7  A: 

rm ./--remove-files.

Note that -- isn't interpreted by the shell, and by extension, escaping it with \ will have no effect.

Logan Capaldo
+1  A: 

The solution is:

rm -- --remove-files

Source: http://www.cyberciti.biz/faq/unix-linux-remove-strange-names-files/

Masi
This is not portable. Logan Capaldo's solution is. Learn both.
Chas. Owens
Chas. Owens: Thank you! I did not know it. What does portability mean? Working in many OSs?
Masi