Delete files with names that appear to begin with '?' in command line

The appropriate way to remove these kind of files is by using the inode value of the file.

Use the following command to get inode value

 ls -li 

 12582925 -rw-r--r--  1 root root   646 May 23 02:19 ?ssolveIncpUL46pK.txt

The first field of the longlisted result is inode value.

Then use the find command to delete the file w.r.t inode.

find . -inum 12582925 -exec rm -i {} \;

The character is not a question mark. The ls utility will replace non printable characters with ?. It is further unclear whether the non printable character really is the first character in the filename or whether there may be one or several spaces before that.

Would you want to delete both those files, you could match the "bad part" with * and then specify the rest of the visible filename more closely:

rm -i ./*ssolve*

This would first expand the given pattern to all the filenames matching it, and then rm would remove them. Be more specific and specify a longer part of the filename if there are files that you don't want to delete that matches the above short pattern, e.g. with

rm -i ./*ssolveIncpUL46pK*

This is assuming that you are located in the same directory as the files that you want to delete.

The -i option to rm makes it ask for confirmation before actually deleting anything.


It is not recommended to use a * to remove files. It could match more than you like.

Being in Debian, the ls (from GNU) command is able to print the values of the files in quoted form[1]:

$ ls -Q
"\nssolve"  "\n\nssolve"  "y"  "z"

Or, even better, list files with quoted names and inodes:

$ ls -iQ
26738692 "\nssolve"  26738737 "\n\nssolve"  26738785 "y"  26738786 "z" 

Then, use rm with the inode number to ensure that only the correct files are removed:

$ find . -xdev -inum 26738737 -exec rm -i {} \;

The call to find is limited to one filesystem (-xdev) to avoid matching a file on other filesystem with the same inode number. Note also that rm is being called with the -i (interactive) option, so it will ask in the command line if each file should be erased.


[1] Note that this do not solve the problem with visually confusing characters like a Cyrillic а ($'\U430') and a Latin a ($'\U61') that look exactly the same but are not. To have a better look at the bytes that a filename is using we need to use an hex viewer;

$ touch а a é $'e\U301' $'\U301'e
$ ls
a  ́e  é  é  а              # what you "see" here depends on your system.

$ printf '<%s>' * | od -An -c
   <   a   >   < 314 201   e   >   <   e 314 201   >   < 303 251
   >   < 320 260   >