-   Linux - General (
-   -   removing file with special characters (

rsashok 02-15-2007 10:44 AM

removing file with special characters
Accidentally a file was created with the name "--some-option", e.g. name starts with two dashes. I can't remove this file from the shell. I tried single and double quotes, escaping leading dashes, but to no avail. All I am getting:
rm: unrecognized option `--some-option'
rm: cannot remove `\\--some-option' No such file or directory

Konqueror removes file without a problem. I tried to search for the answer, but could not find it.

b0uncer 02-15-2007 10:48 AM

It's removed easily:

rm -- --some-option
The two lines (--) tell rm that no more options are given, the next argument is filename.

rsashok 02-15-2007 11:00 AM

Thanks. I didn't know about '--'! But I figure out that I could fool 'rm' by typing path with file name which looks normal:
rm /home/mydir/--some-option

rsashok 02-15-2007 11:07 AM

I check out 'man rm' and of course!!! all this is in the manual:

To remove a file whose name starts with a ‘-’, for example ‘-foo’, use one of these commands:
rm -- -foo
rm ./-foo

Which confirms ancient wisdom: RFM!

znajeeb 02-09-2010 04:08 PM

Remove/delete bad Linux file, having illegal character with inode
First list bad file with inode e.g.

$ ls –il

14071947 -rw-r--r-- 1 znajeeb dba 0 2010-01-27 15:49 \-®Å

Note: 14071947 is inode number.

Now Use find command to delete file by inode:
$ find . -inum 14071947 -exec rm -f {} \;
It will find that bad file and will remove it with force i.e remove without prompt.

All times are GMT -5. The time now is 09:49 PM.