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
  1. aladar% touch "`echo -e "foo\nbar"`" [~/temp/20100827/b]
  2. aladar% ls -i [~/temp/20100827/b]
  3. 531675 foo?bar
  4. aladar% find . -inum 531675 | xargs rm [~/temp/20100827/b]
  5. rm: cannot remove `./foo': No such file or directory
  6. rm: cannot remove `bar': No such file or directory
  7. aladar% find . -inum 531675 -print0 | xargs -0 rm [~/temp/20100827/b]
  8. 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.