How to remove a file using inode number + linux

Post Reply
a24uall
Site Admin
Posts: 166
Joined: Sun Jul 01, 2012 9:07 am

How to remove a file using inode number + linux

Post by a24uall »

Below command list the files and its inode number
ls -il
Example
root@central [~/456]# ls -il
total 12
187957285 drwxrwxr-x 3 root root 4096 Apr 19 22:44 ./
184784128 drwx------ 15 root root 4096 Apr 19 22:44 ../
187957289 -rw-rw-r-- 1 root root 0 Apr 19 22:44 1
187957284 drwxrwxr-x 2 root root 4096 Apr 19 22:44 456.bak/
root@central [~/456]#
Below command is used to delete the file using inode number.
find . -inum [inode-number] -exec rm -i {} \;
Example :
Removing file named "1" with inode number 187957289
[/quote]root@central [~/456]# find . -inum 187957289 -exec rm -i {} \;
rm: remove regular empty file `./1'? y
root@central [~/456]#[/quote]

File removed and you can verify that from below :
root@central [~/456]# ll
total 12
drwxrwxr-x 3 root root 4096 Apr 20 02:25 ./
drwx------ 15 root root 4096 Apr 19 22:44 ../
drwxrwxr-x 2 root root 4096 Apr 19 22:44 456.bak/
root@central [~/456]#
Arun
WebhostingDevelopment.com
Post Reply

Return to “Basic Commands”