Remove file start with special character

December 5th, 2006 mysurface Posted in Common, mv, rm, touch | Hits: 53583 | 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

9 Responses to “Remove file start with special character”

  1. Alternatively, you can use

    rm -- --testing
    touch -- --testing
  2. [...] 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 [...]

  3. [...] Remove file start with special character [...]

  4. Great. First time in ages ive searched google and found the answer in less than 10 seconds.

    cheers mate

  5. dirbacke Says:

    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 {} \;

  6. Thanks God i spent 20 mins to find this blog, finally! going to sub xD

  7. 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.

  8. 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!

  9. try to goes up like one directory above and remove it …. :)

Leave a Reply