Wednesday 3 July 2013

Removing files via inode number

While trying out some code, I accidentally created some files containing meta characters in the filename, which in turn causes problems if you want to remove them. So I dug out an old script I wrote many years ago to delete the file using its inode number. The script has absolutely no error handling or sanitisation, use at your own risk.

#!/bin/bash

inum=$1
echo "Inode: $1"

echo "remove `ls -i | grep $inum`"
rm `ls -i | grep $inum | awk '{ print $2 }' `