Can't delete file with strange name

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:
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.
 
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.
 
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...
 
Sorry for the zombie post, but I had a similar/same issue.

I had a folder that showed up as "????i9?t???1????????".

To get rid of it I opened the current folder in vim: vim . which showed the real folder name as "<fe><ff><ff><8b>i9<eb>t<ff><ff><ff>1<c0><e9><da><fe><ff><ff><83><fd>"
I then removed the <'s and added \x to the hex characters and did this:
rm -rf $(echo -e "\xfe\xff\xff\x8bi9\xebt\xff\xff\xff1\xc0\xe9\xda\xfe\xff\xff\x83\xfd")
 
I have a few ways to kill the file. Some are highly technical though and not for the feint of heart as they require going in with a binary editor and manually deleting the file name. However, it can be done. I need to know what this drive is, what size it is, what format it is, etc.... I know it's msdos format aka some FAT system, but which one?

Here's some methods:

  • Connect the flashcard to the Mac and delete the file there.
  • Try to delete the file on a Windows machine.
  • Reformat the flashcard. This will recreate the filesystem structures on the card.
  • Manually edit the directory and change the offending character(s) to something that can be typed from the keyboard.
That last one, you will need to download editors/bvi in ports/packages. It's a binary file editor with a vi interface. You would specify the drive as the mount point directory: bvi /mount_dir. Then you can search for the filename and manually edit the entry. It will show you the hex as well, so you can probably specify something like \0xFF or something like that on the command line. I do not use tcsh, so I'm not sure how you would specify binary characters in that shell.
 
it is really funny to see this post is from 2010 !

Anyhow, the method i always use to delete ugly named files is by skipping the shell
and using a scripting language. I always used Python for this in the past, but lately i love more Ruby. So, here the example is in Ruby.

The key commands are these :
1] enter the ruby REPL = > irb
--> now i suppose you are in IRB REPL, you can quit with Ctrl-c
2] get the current directory with Dir.pwd
3] move to other directories with e.g. Dir.chdir "tmp"
4] get list of files in current directoriy Dir.glob "*"
5] Suppose you see in the list the silly file name, let it be [ ...."bar", "ABC $#`'{}" , "foo" ... ]
6] Copy the ugly name
7] Remove the file File.delete "ABC $#`'{}"
8] Quit IRB with Ctrl-C

It is useful to have command completion in IRB, for that you can type in IRB
require 'irb/completion', then if you start to like Ruby, put that command
in the file '~/.irbrc'.

P.S. tested in Ruby2.4.4.

bye
n.
 
I'm kinda surprised that the obvious solution that was already posted didn't catch on. The rm -i * solution is just perfect since it uses the shell's globbing (which will catch all the weird names) to go trough all the files in the directory and you get to review everyone of them before deciding to delete them.
 
I'm kinda surpised that the obvious solution that was already posted didn't catch on. The rm -i * solution is just perfect since it uses the shell's globbing (which will catch all the weird names) to go trough all the files in the directory and you get to review everyone of them before deciding to delete them.
Hah, good to know :) I remember having somewhat similar problem. It was mainly on the mounted Windows-handled disks/USB sticks or files extracted from the Windows-created archives. With these my solution was to mount the msdosfs using the proper locale.
 
I'm kinda surprised that the obvious solution that was already posted didn't catch on. The rm -i * solution ...

I remember I used that solution many many years ago, when you have more than 30 file in a directory it becomes boring and, I remember I was typing, no no no no no, so many times I was doing it also in the entry I wanted to delete.

Also, the risk of mistyping the "-i" and delete all is very high.

bye
n.
 
Yes that's true but usually it's just one or two files with weird names because of some accident or the files are from a foreign source with file names in foreign language.
 
true kpa, usually only a few files have ugly names. as you say it can be a matter of language.

But consider, they may be placed in a dir. containing many files. Interactively, you should type yes/no untill you arrive at the desider file. wich is boring and error prone.
(sure, you may refine the pattern *)

Also, you may want to rename the file instead of deleting. Even if this option is not on topic, it happens;)

I can not check my statements, writing on phone, but i guess i remember well.

i reccomend everybody to try the scriping language REPL way. it is using a cannon to shoot a mosquito. but along years, i found it to be a fast, flexible, not disaster prone and an easy to remember strategy.

bye from Moscow holiday:)
 
Back
Top