Delete File By inode Reference

9th May 2008 - 1 minute read time

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

Permalink
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]

 

Anonymous (Fri, 08/27/2010 - 14:02)

Add new comment

The content of this field is kept private and will not be shown publicly.