≡ Menu

Linux – Delete files with inode number

The question – I accidentally created a few files with unusual names and I am unable to delete them using the rm command. Is there a way to delete the files in some other way?

You can delete the files using the inode number. An inode entry in the inode table contains a unique inode number and other statistics of the file including the owner, permissions etc.

You can use the find command to delete a file by its inode number. The find command takes an argument of the form -inum which can be used to find files by the inode number.

First, you need to find the inode number of the file that you want to delete. To do this, run the following command:

[root@server java]# ls -ila
total 10084
140349992 drwxr-xr-x  2 root root     4096 Oct 10 15:25 .
140315666 dr-xr-x--- 11 root root     4096 Oct 10 12:44 ..
  5179680 -rw-r--r--  1 root root 10294930 Sep 19 21:13 php-5.5.4-1.fc20.src.rpm
  5179683 -rwxr-xr-x  1 root root      107 Oct 10 15:17 root.sh
[root@server java]#

The first column in the output of ls is the inode number. Say I want to delete the file root.sh. This can be achieved using the following command:

[root@server java]# find . -inum 5179683 -delete
[root@server java]# ls -lai
total 10080
140349992 drwxr-xr-x  2 root root     4096 Oct 10 15:31 .
140315666 dr-xr-x--- 11 root root     4096 Oct 10 12:44 ..
  5179680 -rw-r--r--  1 root root 10294930 Sep 19 21:13 php-5.5.4-1.fc20.src.rpm
[root@server java]#

The find command is a very versatile command. For further reading on the find command parameters, I suggest you read this article.

Incoming search terms:

  • Linux FC 20 delete file by inode (1)

{ 0 comments… add one }

Leave a Comment