Removing stubborn files with backslashes and other special characters in Linux

A frusterated business woman in front of a laptop making a face

We recently had to remove a file with a pretty odd file name: "\ я\ 005-2.jpg".

Normally, you can deal with oddities (such as spaces in file names) by just putting the file in quotes and removing normally like...

rm -rf "\ я\ 005-2.jpg"

However, when it comes to backslashes and other special characters in file names, things get tricky.

The way to remove a file like the above is to first find the Inode number. You can do this in one of two ways:

First, using \ я\ 005-2.jpg as an example, you can run stat from the command line.

stat \ я\ 005-2.jpg This will give you an output that looks like this: File: ` я 005-2.jpg' Size: 150029 Blocks: 304 IO Block: 4096 regular file Device: 10302h/66306d Inode: 13770830 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 502/ green) Gid: ( 502/ green) Access: 2013-07-08 12:46:49.000000000 -0700 Modify: 2011-02-26 04:23:09.000000000 -0800 Change: 2013-07-11 09:47:57.000000000 -0700

A second option is to run ls -li as in...

ls -li \ я\ 005-2.jpg

This will give you an output like this:

13770830 -rwxr-xr-x 1 green green 150029 Feb 26 2011 \ я\ 005-2.jpg

In either event, you can see that the Inode value is 13770830.

To get rid of the troublesome \ я\ 005-2.jpg (a.k.a. 13770830) use the find command and tell it to remove by Inode as in -exec rm -i. For example:

find . -inum 13770830 -exec rm -rf {} \;

Farewell \ я\ 005-2.jpg, we hardly knew ya.