• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Can't delete file with strange name

sidetone

Aspiring Daemon

Thanks: 308
Messages: 895

#76
Now I'm having this problem. This happened when using emulators/i386-wine to install a Windows CD, then it caused errors, so I tried to delete it all for a fresh install. This error didn't happen when I was running emulators/wine from a 32bit processor. So I wonder if the difference in the numerical system has something to do with the text not being recognized.

Trying midnight commander didn't work here. The terminals nor midnight commander didn't recognize the text at all. From the upper level directory I tried rm -r <directory> and it gives
Code:
rm : <file names> : invalid argument
I'm still able to move the directory folder containing these odd named files, but not to another filesystem, in this case a RAM filesystem. (please don't explain to me how this thread is 3 or 5 years old)

Without unmounting I did mount -t tmpfs tmpfs /<directory>/<directory> on the directory with bad filenames, and rebooted. It worked for me.
 
Last edited by a moderator:

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,125
Messages: 27,000

#78
What worked for me was:
rm ./?
Careful with that one. This also deletes any and all single letter filenames in the current directory. So it's quite possible to delete a lot more than intended.

Code:
dice@maelcum:~/test % touch a
dice@maelcum:~/test % touch b
dice@maelcum:~/test % touch c
dice@maelcum:~/test % touch \?
dice@maelcum:~/test % ll
total 2
-rw-r--r--  1 dice  dice  0 Nov  8 18:29 ?
-rw-r--r--  1 dice  dice  0 Nov  8 18:29 a
-rw-r--r--  1 dice  dice  0 Nov  8 18:29 b
-rw-r--r--  1 dice  dice  0 Nov  8 18:29 c
dice@maelcum:~/test % rm ./?
dice@maelcum:~/test % ll
total 0
The proper way would be to escape the ?:
Code:
dice@maelcum:~/test % touch a
dice@maelcum:~/test % touch b
dice@maelcum:~/test % touch c
dice@maelcum:~/test % touch \?
dice@maelcum:~/test % ls -al
total 4
drwxr-xr-x  2 dice  dice   6 Nov  8 18:30 .
drwxr-xr-x  6 dice  dice  22 Nov  6 18:54 ..
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 ?
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 a
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 b
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 c
dice@maelcum:~/test % rm \?
dice@maelcum:~/test % ls -al
total 4
drwxr-xr-x  2 dice  dice   5 Nov  8 18:30 .
drwxr-xr-x  6 dice  dice  22 Nov  6 18:54 ..
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 a
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 b
-rw-r--r--  1 dice  dice   0 Nov  8 18:30 c
You can also quote it (single quotes): rm '?'

The reason is that, similar to *, the question mark has a special meaning for the shell (both sh(1) and csh(1) behave this way). Thus it needs to be escaped or quoted in order to be taken literally.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,125
Messages: 27,000

#80
The problem with the OP's files is that the '?' doesn't mean a literal question mark but is a placeholder for some unprintable character. You can get in a situation like that if the filenames have been created with a different codepage or with unicode and are being presented on an ASCII system that doesn't translate the codepage/unicode correctly.
 

poorandunlucky

Well-Known Member

Thanks: 26
Messages: 359

#81
The problem with the OP's files is that the '?' doesn't mean a literal question mark but is a placeholder for some unprintable character. You can get in a situation like that if the filenames have been created with a different codepage or with unicode and are being presented on an ASCII system that doesn't translate the codepage/unicode correctly.
What I mean is that the thread was posted in 2015, and the OP just stopped updating us on what was going on...
 
Top