How to remove a directory or file with special characters in Solaris

I finally figured out how to remove a file or directory with special characters in the name. It's kind of rudimentary so I thought I would share it with everyone:

find .inum [number] -exec rm -rf {} \;

find /path -inum [number] -exec rm -rf {} \;

Note: there are syntax errors in the above post. The -r also is potentially dangerous if the file is a directory - all of the subdirectories and files will be deleted as well.

2 Likes

Personally I would rename the directory to something sensible and avoid passing strange filenames to powerful commands like "rm".

Btw. The posted "find" commands could be improved with a "-xdev" (or in some older versions "-mount") parameter because inode numbers are only unique within a filesystem.

Thanks for clearifying that all subdirectories and files will be deleted as this was my intention. I put the . and didn't add the -inum either. If any body has a better way to do this then please post or if you have a way to delete the directories without deleting all the contents within the directory than please post. I've tried way too many ways so be prepared for some constructive criticism if I find a way that does not work.

It is not possible to delete a directory which is not empty.

Is you problem confined to directory names which contain special characters?

Actually my problem was with removing directories with names that began with special charaters and ending with special characters. Any help with this would be great as I was able to get around the problem at first by changing the directory to a name that didn't begin with special characters by saying:

 
find . -inum [number] -exec mv {} ./del \;

Then I just did the rmdir -r command.

Warning warning Will Robinson. Scary script.

Correspondents reading this post please be aware that this script is not for general use. It does not contain a "-xdev" (or "-mount" for some versions of unix) parameter which would prevent the script moving files with matching inode number from all filesystems it encounters during the "find".

Nuff said.

easier way:

# ls
    @#hello
    world
# rm **hello
# ls
   world
#