Entries Tagged as ''

Remove Files By Inode Number (Linux/UNIX/Mac OS X)

Recently I needed to delete some pesky files that at some point managed to get created. The problem with these ‘pesky’ files is that they don’t have file-friendly names. One of the files was named “!” (no quotes), and another was “-20080605.log”

I know I could remove them by using the rm command prefixing the unacceptable characters with “\” but I also recall a method to remove files by their inode number.

$ rm \!; rm -20080606.log;

For a refresher, a quick google gave me this resourceful site.

In summary:

1. Get the inode number of the file you want…

$ ls -li

Output:

2396291 -rw-rw-r– 1 user user 35 2008-06-05 09:37 -20080605.log

The inode number is 2396291.

2. Delete the file using the inode number found from step 1.

$ find . -inum 2396291 -exec rm -i {} \;