At times you may encounter a problem where you can not able to delete a file using their file name

General methodology to remove a file in unix “rm <file name>. In other words, A unique number would be assigned to each file which is called inode number

Lets see, how a file can be deleted using inode number

1) Use -i flag to get the inode number of any file (First column is your inode)
# ls -li

2) In find command, use -inum flag with inode number and ls at the end to list a file
# find . -inum <inode number> -ls

3) In find command, use -inum flag with inode number and pass the rm using exec arugment to delete a file
# find . -inum <inode number> -exec rm {} \;
Example:-
1847 0 -rw-r–r– 1 root system 0 Feb 28 15:27 -z_file

In above example , the inode number is 1847. Simply remove it using the find command and the -exec argument:

# find . -inum 1847 -ls
1847 0 -rw-r–r– 1 root system 0 Feb 28 15:27 ./-z_file

# find . -inum 1847 -exec rm {} \;

Now, You can use ls command and verify that file has been removed successfully

Advertisements