how to remove a file named “?” in linux? [closed]

how to remove a file named “?” in linux? [closed]

I created a file named “?”, is anybody know how to delete it?
It seems that ? is a special character in linux, I use Redhat as my OS.
I have already tried
rm ?
rm “?”
rm \?

They all failed and I got the error indicated that the file doesn’t exist.


Solution 1:

find the inode of the file:

ls -li

then delete the file using inode:

find . -inum <inode-number> -exec rm -i {} \;

BTW, rm ? works for me fine. here is my bash version:

# bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

Solution 2:

rm \? and rm "?" are both perfectly good ways to delete a file named ?. If they didn’t work, and you still seem to have a file name ?, then it is most likely that the ? being shown is not really a ?, but rather the result of substituting an unprintable character with a ?. To see what the file is really called (with GNU ls) try:

ls --quoting-style=escape

Solution 3:

Use this rm command to remove a file named ?:

rm ./\?

OR from another directory:

rm /path/to/\?

Solution 4:

You can delete the file by its inode number. see the output bellow:

alplab:~/cad# ls -il
63051 -rw-r--r--    1 root     root             0 Nov 12 11:48 ?
alplab:~/cad# find . -inum 63051 -exec rm -i {} \;

I used the “find” command to delete the file with the inode number 63051 (the inode belonging to my “?” file).


Related:  Allocating more memory than there exists using malloc