Using inode number to delete files with unusual names

The problem:

So a couple of days ago this happened:

% ls -lh |grep 033
-rw-r--r-- 1 jsvd users 71K May 25 15:05 `\033

Yeah.. “What the hell is that?” was my first thought. The second was “How do I delete this?”

I tried the usual tricks to delete files with weird characters, to no avail:

% rm ./`\033
`bquote> 
% rm "\`\\033"
rm: cannot remove ‘`\\033’: No such file or directory
% rm "\`\033"
rm: cannot remove ‘`\\033’: No such file or directory
% rm "*033"
rm: cannot remove ‘*033’: No such file or directory

The solution:

The only way I was able to delete the file was through the inode:

% ls -lhi |grep 033
 50105 -rw-r--r-- 1 jsvd users  71K May 25 15:05 `\033
%

OK so now that I have the inode of the misbehaved file, let’s confirm we can find it by the inode:

% find -inum 50105
./`?
%

Ermm..yep that’s it. Just pipe it to rm and be done with it:

% find -inum 50105 | xargs rm
%

Is it gone?

% find -inum 50105
%

Success!

About these ads

One comment to Using inode number to delete files with unusual names

  1. I usually employ Midnight Commander for these weird files :D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s