Removing file or directory via inode number
While back I was doing some work with SVM. Everything went smoothly, but after I was done I experienced some bizarre issue. I am not entirely sure how it came to be. I needed to remove a temporary mountpoint called /tmpmnt:
bash-3.00# ls -l
lrwxrwxrwx 1 root root 9 Nov 29 2010 bin -> ./usr/bin
drwxr-xr-x 8 root sys 512 Nov 29 2010 boot
drwxr-xr-x 3 root nobody 512 Nov 30 2010 cdrom
drwxr-xr-x 18 root sys 4096 Jun 8 10:04 dev
drwxr-xr-x 2 root sys 512 Jun 8 2011 devices
drwxr-xr-x 88 root sys 4608 Jun 8 10:04 etc
drwxr-xr-x 3 root sys 512 Nov 30 2010 export
dr-xr-xr-x 1 root root 1 Jun 8 10:04 home
drwxr-xr-x 18 root sys 512 Nov 29 2010 kernel
drwxr-xr-x 8 root bin 5632 Nov 29 2010 lib
drwx------ 2 root root 8192 Nov 29 2010 lost+found
drwxr-xr-x 2 root sys 512 Nov 29 2010 mnt
dr-xr-xr-x 1 root root 1 Jun 8 10:04 net
drwxr-xr-x 5 root sys 512 Nov 30 2010 opt
drwxr-xr-x 5 root sys 512 Nov 29 2010 platform
dr-xr-xr-x 40 root root 128448 Jun 8 10:09 proc
drwxr-xr-x 2 root sys 1024 Nov 29 2010 sbin
drwxr-xr-x 4 root root 512 Nov 29 2010 system
drwxrwxrwt 4 root sys 256 Jun 8 10:09 tmp
drwxr-xr-x 2 root root 512 Jun 8 10:09 tmpmnt
drwxr-xr-x 40 root sys 1024 Nov 29 2010 usr
drwxr-xr-x 45 root sys 1024 Nov 29 2010 var
dr-xr-xr-x 6 root root 512 Jun 8 10:04 vol
But when I tried to do rm -Rf on the directory I got No such file or directory:
bash-3.00# rm -Rf ./tmpmnt
./tmpmnt: No such file or directory
I tried mv-ing the file and who knows what else, but I still could not get rid of that mountpoint. I figured maybe something has gone wrong with the filesystem. However, fsck returned with no problems. So, now what?
It happens that find command has this nice parameter called -inum. I could do find for the inode number of the directory and remove it with -exec parameter. First I got the inode number:
bash-3.00# ls -li
1747 lrwxrwxrwx 1 root root 9 Nov 29 2010 bin -> ./usr/bin
66 drwxr-xr-x 8 root sys 512 Nov 29 2010 boot
327353 drwxr-xr-x 3 root nobody 512 Nov 30 2010 cdrom
1805 drwxr-xr-x 18 root sys 4096 Jun 8 10:04 dev
3568 drwxr-xr-x 2 root sys 512 Jun 8 2011 devices
226 drwxr-xr-x 88 root sys 4608 Jun 8 10:04 etc
4 drwxr-xr-x 3 root sys 512 Nov 30 2010 export
14782 dr-xr-xr-x 1 root root 1 Jun 8 10:04 home
3087 drwxr-xr-x 18 root sys 512 Nov 29 2010 kernel
1918 drwxr-xr-x 8 root bin 5632 Nov 29 2010 lib
3 drwx------ 2 root root 8192 Nov 29 2010 lost+found
1926 drwxr-xr-x 2 root sys 512 Nov 29 2010 mnt
327217 dr-xr-xr-x 1 root root 1 Jun 8 10:04 net
1927 drwxr-xr-x 5 root sys 512 Nov 30 2010 opt
51 drwxr-xr-x 5 root sys 512 Nov 29 2010 platform
1928 dr-xr-xr-x 40 root root 128448 Jun 8 10:10 proc
1929 drwxr-xr-x 2 root sys 1024 Nov 29 2010 sbin
1934 drwxr-xr-x 4 root root 512 Nov 29 2010 system
1937 drwxrwxrwt 4 root sys 298 Jun 8 10:10 tmp
326783 drwxr-xr-x 2 root root 512 Jun 8 10:09 tmpmnt
31 drwxr-xr-x 40 root sys 1024 Nov 29 2010 usr
6 drwxr-xr-x 45 root sys 1024 Nov 29 2010 var
327300 dr-xr-xr-x 6 root root 512 Jun 8 10:04 vol
Then came the actual command to remove the file:
bash-3.00# find . -inum 326783 -mount -exec rm -Rf {} \;
bash-3.00# ls -l
lrwxrwxrwx 1 root root 9 Nov 29 2010 bin -> ./usr/bin
drwxr-xr-x 8 root sys 512 Nov 29 2010 boot
drwxr-xr-x 3 root nobody 512 Nov 30 2010 cdrom
drwxr-xr-x 18 root sys 4096 Jun 8 10:04 dev
drwxr-xr-x 2 root sys 512 Jun 8 2011 devices
drwxr-xr-x 88 root sys 4608 Jun 8 10:04 etc
drwxr-xr-x 3 root sys 512 Nov 30 2010 export
dr-xr-xr-x 1 root root 1 Jun 8 10:04 home
drwxr-xr-x 18 root sys 512 Nov 29 2010 kernel
drwxr-xr-x 8 root bin 5632 Nov 29 2010 lib
drwx------ 2 root root 8192 Nov 29 2010 lost+found
drwxr-xr-x 2 root sys 512 Nov 29 2010 mnt
dr-xr-xr-x 1 root root 1 Jun 8 10:04 net
drwxr-xr-x 5 root sys 512 Nov 30 2010 opt
drwxr-xr-x 5 root sys 512 Nov 29 2010 platform
dr-xr-xr-x 40 root root 128448 Jun 8 10:38 proc
drwxr-xr-x 2 root sys 1024 Nov 29 2010 sbin
drwxr-xr-x 4 root root 512 Nov 29 2010 system
drwxrwxrwt 4 root sys 338 Jun 8 10:38 tmp
drwxr-xr-x 40 root sys 1024 Nov 29 2010 usr
drwxr-xr-x 45 root sys 1024 Nov 29 2010 var
dr-xr-xr-x 6 root root 512 Jun 8 10:04 vol
As you can see the directory was gone. I ran fsck again, just in case and again I got no errors back.