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
scritps010/010/010/010

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 {} \;

About Andrew Lin

Hi, I have always wanted to creat a blog site but never had the time. I have been working in Information Technology for over 15 years. I specialize mainly in networks and server technologies and dabble a little with the programming aspects. Andrew Lin

View all posts by Andrew Lin →