How to delete a file named "?" on Linux?

I created a file called "?", Does anyone know how to delete it?

It seems that? is a special symbol in Linux, I use Redhat as my OS.

I have already tried

rm ? rm "?" rm \? 

All of them failed, and I received an error message that the file does not exist.

+7
linux bash command
source share
4 answers

find the file index:

 ls -li 

then delete the file using inode:

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

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

 # bash --version GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu) 
+13
source share

rm \? and rm "?" are both great ways to delete a file with a name ? . If they do not work and you still have a file name ? then most likely displayed ? not really ? , but rather the result of replacing the non-printable character with a ? . To find out what the file is really called (using GNU ls ), try:

 ls --quoting-style=escape 
+3
source share

Use this rm command to delete a file named ? :

 rm ./\? 

OR from another directory:

 rm /path/to/\? 
+1
source share

You can delete the file using inode . see below:

 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 inode number 63051 (the inode belonging to my file ??).

0
source share

All Articles