Remove file start with special character
December 5th, 2006 mysurface Posted in Common, mv, rm, touch | Hits: 49568 | 9 Comments »
In linux, file can be any name, including “–testing”. If you have a file with this name, how you delete it?
Command line bellow will fail,
rm --testing
The correct one is
rm ./--testing
This works for mv, cp etc. So you can actually create a file with name “–testing” using touch.
touch ./--testing







December 6th, 2006 at 11:15 pm
Alternatively, you can use
March 21st, 2007 at 8:54 pm
[...] Sometimes, you may find some file you can’t delete because of the filename begins with minus(-). LBE have that example on the post “Remove file start with special character”, as simple as this [...]
October 6th, 2007 at 1:25 pm
[...] Remove file start with special character [...]
August 8th, 2010 at 7:43 pm
Great. First time in ages ive searched google and found the answer in less than 10 seconds.
cheers mate
May 6th, 2011 at 4:07 pm
The above will not work for all files, the best thing is to find the inode number.
First list bad file with inode e.g.
$ ls –il
Output
1453594 -rw-r–r– 1 dirbacke dba 0 2011-05-06 10:03 \-®Å
Note: 1453594 is inode number.
Now Use find command to delete file by inode:
$ find . -inum 1453594 -exec rm {} \;
It will find that file with special character and remove it. If you want to remove without prompting and force remove even directories, then type
$ find . -inum 1453594 -exec rm -rf {} \;
May 19th, 2011 at 1:49 am
Thanks God i spent 20 mins to find this blog, finally! going to sub xD
May 19th, 2011 at 3:03 am
keep up the great work , I read few posts on this website and I believe that your web blog is rattling interesting and has got lots of good information.
July 20th, 2011 at 7:51 pm
After reading it I thought it was extremely enlightening. I appreciate you spending some time and effort to place this post along. Just as before I find myself shelling out excessively much time both browsing and writing comments. But so what, ?t had been still of great benefit!
August 16th, 2011 at 2:44 pm
try to goes up like one directory above and remove it …. :)