Sunday, February 18, 2007

Delete a Filename with an Invalid Character

Once in awhile, you will have to delete a file name that was created with an invalid character. Frankly speaking, this can be a little tricky to deal with.

Here is an example. This is a filename with an invalid character, "-", in front of it.

# cd /tmp
# ls
-esofthub
# rm /-esofthub
or
# rm -- -esofthub

or by inode
# ls -i
# find . -inum 968746 -exec rm -i {} \;

6 comments:

WR said...

Thanks. I've had to use this twice so far.

esofthub said...

I appreciate the comment and glad the post was able to help you.

Will said...

Hey thanks. I had a file named \ (backslash).

to get rid of it:

rm -i {} \;

worked.

Anonymous said...

this really helped a lot
thanks!
- hectorjohn@yahoo.com

esofthub said...

hectorjohn,

I'm glad you found it useful and thank you for your comment.

Roy

Chu-Cheng Hsieh said...

This is really cool! It help me a lot to delete these wired files. Thanks for posting it.