How to delete a file or directory with special characters using the inode in Unix or Linux

My fat fingers inadvertently created a directory on my unix server with special characters. I could not access this directory nor could I delete it. When I listed the directory using the command ls –b, I could see all the funny characters.

ls –b

I tried every command I could think of, rmdir “scripts”, rmdir “scripts010/010/010/010”. The only way to remove this directory was to delete it using the inode number.

To determine the inode use the -i option with the ls command.
ls –i
184538 scritps

Below is the command syntax to delete the directory.
find . –inum 184538 –exec rmdir {} \;

If you wanted to delete a stubborn file then simply substitute rmdir with rm.
find . –inum 184538 –exec rm {} \;

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *