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
# rm /-esofthub
# rm -- -esofthub

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


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


Anonymous said...

this really helped a lot

esofthub said...


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


Chu-Cheng Hsieh said...

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