How to remove files with special characters in Linux

Solution 1

To remove a file with dashes, slashes or other special characters, the easiest way is to access the file using its inode. To get the inode of a file, just do a ls -li. When you have that number, use find to delete the file using the following command:

find . -inum [inode] -exec rm -i {} \;

Solution 2

To remove a file whose name starts with a `-‘, for example `-foo', use one of these commands:

rm --- -foo
rm ./-foo

so,

$ rm --- -\,my\?\ funky.file\$name

Via Johnny chadda

Sponsored Link

Incoming search terms:

Related posts

2 thoughts on “How to remove files with special characters in Linux

  1. I was always wondering how to do it from the command prompt… The “easy” way was to use mc (midnight commander) to do it. Thank for the nice trick. :)

    [Reply]

Leave a comment

Your email address will not be published. Required fields are marked *