Delete File By inode Reference

If you want to delete a file that you can't type in the name of either because the name is long and complicated, or because it is difficult to type in without causing a syntax error then here is the solution.

You first need to find the inode reference of the file. This can be done by using the command ls -li. The start of each line has a number that is specific to that file. You could use the command ls -i , but the output is a little confusing.

To delete the file use the find command with the flag -inum, followed by a pipe into the rm (remove file) command like the following.

find . -inum 916618 | xargs rm

The xargs bit is used to pass a list of the files found from the find command to the rm command.

Comments

aladar% touch "`echo -e "foo\nbar"`"                        [~/temp/20100827/b]
aladar% ls -i                                               [~/temp/20100827/b]
531675 foo?bar
aladar% find . -inum 531675 | xargs rm                      [~/temp/20100827/b]
rm: cannot remove `./foo': No such file or directory
rm: cannot remove `bar': No such file or directory
aladar% find . -inum 531675 -print0 | xargs -0 rm           [~/temp/20100827/b]
aladar% ls                                                  [~/temp/20100827/b]

 

Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
10 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.