Removing files with odd names dashes etc.. linux

Sometimes, perhaps due to script errors etc.. you can end up with files which have a dash (-) or other unusual symbol in.

Removing them with the traditional rm -filename doesn’t work as rm takes the dash to be an option -filename is not a valid option, so it will error.

So how can you remove these files then?

Well its simple, just specifiy the full path, or the full relative path.

For example, say you have  a file called -file and its located in /root/

rm -file will fail, but you can either do rm ./-file or rm /root/-file

Easy peasey

If you found this article useful, please click on 1 or 2 of the adverts, it helps me to keep the site up and running.

Thanks!

You can follow any responses to this entry through the RSS 2.0 feed.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This blog is kept spam free by WP-SpamFree.