# Can't delete file with strange name



## sverreh (May 29, 2010)

I have copied some files from a Macbook to a flashcard, and now I want to delete them from the card using my FreeBSD machine. Some files have strange characters in them, and I am unable to delete them. I have searched the forums, but not found a solution. Here is a list of things I have tried:


```
sverre % ls
Vivian?3
sverre % ls -l
ls: Vivian?3: Invalid argument
total 0
sverre % rm -- Vivian?3
rm: No match.
sverre % rm *
Do you really want to delete all files? [n/y] y
rm: No match.
sverre % rm ./Viv*
rm: No match.
sverre % rm -- Viv*
rm: No match.
sverre % rm -f -- Viv*
rm: No match.
sverre % find . -name Viv\* -exec rm -- {} \;
find: ./Vivian?3: Invalid argument
```

I am not able to rename the file either:


```
sverre % mv Vivian?3 Viv
mv: No match.
```

I have no more tricks in my bag. Any ideas?


----------



## graudeejs (May 29, 2010)

try this:
in terminal with shell, that can complete names, type *rm -f Vi* and hit tab
That may work
also you may want to try same but using single quotes


----------



## dennylin93 (May 29, 2010)

I've also encountered this problem before. I worked around it by using the file manager under GNOME. The delete works flawlessly.


----------



## sverreh (May 29, 2010)

killasmurf86 said:
			
		

> try this:
> in terminal with shell, that can complete names, type *rm -f Vi* and hit tab



Thanks for the idea killasmurf! Unfortunately, the filename completion gives the same weird filename, and the result is the same both with and without single quotes.

@dennylin93: I don't use Gnome, so I tried to follow your advice by firing up konqueror as file manager. Unfortunately, it shows *no* files in the directory where the strange file is.
What is the name of the file manager you used?


----------



## graudeejs (May 29, 2010)

it might look like same, but shell might interpret it correctly.
It worked for me, when I had some weird characters, that I just couldn't type.
That time I selected text with mouse to copy it later. It worked. [However it is not bulletproof method]
so even if you still see the same, try doing it.

As for your last question to dennyling93, he probably use nautilus (default gnome FM)
you can try x11-fm/rox-filer, it's pretty light-width, or x11-fm/gentoo also very light-width


----------



## lbol (May 29, 2010)

what type of shell are you using?

Try to put the file name in quotes
`$ rm 'strange file name'`


----------



## sverreh (May 29, 2010)

killasmurf86 said:
			
		

> so even if you still see the same, try doing it.
> 
> As for your last question to dennyling93, he probably use nautilus (default gnome FM)
> you can try x11-fm/rox-filer, it's pretty light-width, or x11-fm/gentoo also very light-width



Of course I tried it, but unfortunately, it didn't work for me. I will give your suggested Fm's a try, and report back. Thanks!

@ibol:  I use tcsh. I tried with single quotes, no luck! Thanks for trying, anyway!


```
sverre % rm -- 'Vivian?3'
rm: Vivian?3: Invalid argument
```


----------



## lbol (May 29, 2010)

what about `$ rm -i *`
Option -i will ask for confirmation before removing a file

I am not using tcsh but you could try sh


----------



## copypaiste (May 29, 2010)

midnight commander handles these horrors in filenames quite nicely.


----------



## fronclynne (May 29, 2010)

Have you tried [cmd=""]rm Vivian\?3[/cmd]?

Failing that, [cmd=""]ls -i[/cmd] should give you an inode to work with and using fsdb(8) (Vorsicht!  it is really easy to royally screw up on entire filesystem with fsdb, be super careful!) with "clri" should let you delete it.

Seriously, though:  be very careful.


----------



## wblock@ (May 29, 2010)

sverreh said:
			
		

> Of course I tried it, but unfortunately, it didn't work for me. I will give your suggested Fm's a try, and report back. Thanks!
> 
> @ibol:  I use tcsh. I tried with single quotes, no luck! Thanks for trying, anyway!
> 
> ...



Usually escaping weird characters with a backslash should work.  Outside of single quotes, anyway; but filename completion should have brough it up that way.

Given how resilient this has been, maybe it's some type of locale or language thing, with the ? actually being a special character or the first of a two-byte character.


----------



## Carpetsmoker (May 29, 2010)

> sverre % rm -- Vivian?3



Something like this will never work, the '?' is interpreted by tcsh, meaning "match any character once".
Use either single quotes or an escape character (\?).

Try setting your terminal to UTF-8.


----------



## sverreh (May 29, 2010)

You guys are incredibly helpful. I will come back and test your suggestions tomorrow!
Thanks to all for trying to help!


----------



## adamk (May 29, 2010)

Perhaps it's even a filesystem error.  Have you fsck'ed it lately?

Adam


----------



## sverreh (May 31, 2010)

So, I have tried some more.

@Killasmurf:



> you can try x11-fm/rox-filer



I installed rox-filer, but was unable to make it run. Complained about an error in libglad, I think. I am not able to repeat it now, because for some reason installing it seemed to mess up my Xorg. :r 

@Ibol:



> what about $ rm -i *




```
sverre % rm -i *
rm: No match.
```

@copypaiste



> midnight commander handles these horrors in filenames quite nicely.



I will try that. First I will have to get my system back to normal after I managed to mess it up so badly that Xorg doesn't work. :r

@fronclynne:



> Have you tried rm Vivian\?3




```
sverre % rm Vivian\?3
rm: Vivian?3: Invalid argument
```



> ls -i
> should give you an inode to work with and using fsdb(8)




```
sverre % ls -i
ls: Vivian?3: Invalid argument
```

No luck! Anyway, your warning about fsdb(8) sounded so scary that I doubt I would have the courage to use it! 

@wblock:



> Given how resilient this has been, maybe it's some type of locale or language thing, with the ? actually being a special character or the first of a two-byte character.



You may very well be right. If this is the case, what can I do?

@Carpetsmoker:



> Something like this will never work, the '?' is interpreted by tcsh, meaning "match any character once".



You are right. I have just proved it! 


> Use either single quotes or an escape character (\?).



Unfortunately, that doesn't work either.



> Try setting your terminal to UTF-8.



How do I do that? 

@adamk:


> Perhaps it's even a filesystem error. Have you fsck'ed it lately?



No, I haven't done that. Maybe I will try that later if nothing else helps.


----------



## Alt (May 31, 2010)

You can delete such bad names with command
	
	



```
find . -name Viv\* -delete
```


----------



## sverreh (May 31, 2010)

Alt said:
			
		

> You can delete such bad names with command
> 
> 
> 
> ...



I already tried to use find, in a slightly different way. (See my first post.) I tried your suggestion now, and it gives the same result. find does not like my filename either. This must be a really ugly (but interesting) filename!  Here is the result:

```
sverre % find . -name Viv\* -delete
find: ./Vivian?3: Invalid argument
sverre %
```

Thanks for trying!


----------



## sverreh (May 31, 2010)

adamk said:
			
		

> Perhaps it's even a filesystem error.  Have you fsck'ed it lately?



I ran fsck on the flashcard. I don't do this kind of thing very often, and am a little bit puzzled: I can't make fsck answer yes, or prompt for an answer to the qustions it asks. It seems that no matter which options I give, it always decides to answer "no". 


```
# fsck -y -t msdosfs /dev/da0s1
** /dev/da0s1 (NO WRITE)
** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Checking Directories
** Phase 4 - Checking for Lost Files
Next free cluster in FSInfo block (2) not free
Fix? no
60 files, 3905504 free (122047 clusters)
MARK FILE SYSTEM CLEAN? no

***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****
#
```

I also did the check with fsck_msdosfs, and got the same result. I guess that's because fsck runs fsck_msdosfs when I give 
	
	



```
-t msdosfs
```


```
# fsck_msdosfs -y /dev/da0s1
** /dev/da0s1 (NO WRITE)
** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Checking Directories
** Phase 4 - Checking for Lost Files
Next free cluster in FSInfo block (2) not free
Fix? no
60 files, 3905504 free (122047 clusters)
MARK FILE SYSTEM CLEAN? no

***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****
#
```

Anyway, does this output indicate an error in the filesystem?


----------



## sverreh (May 31, 2010)

Carpetsmoker said:
			
		

> Try setting your terminal to UTF-8.



Do you mean:
`$ xterm -en UTF-8`

I tried this, with the same negative result. I also tried

`$ xterm -u8`

but to no avail.


----------



## john_doe (May 31, 2010)

sverreh said:
			
		

> ```
> # fsck -y -t msdosfs /dev/da0s1
> ** /dev/da0s1 (NO WRITE)
> ```


Did you umount(8) it before running fsck?


----------



## sverreh (May 31, 2010)

john_doe said:
			
		

> Did you umount(8) it before running fsck?



No, good point!

Tried without mounting it now:

```
#  fsck -y -t msdosfs /dev/da0s1
** /dev/da0s1
** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Checking Directories
** Phase 4 - Checking for Lost Files
Next free cluster in FSInfo block (2) not free
Fix? yes
60 files, 3905504 free (122047 clusters)
MARK FILE SYSTEM CLEAN? yes
MARKING FILE SYSTEM CLEAN
#
```

Much better! So that means the file system is OK?
But I still can't delete this little bugger! Thanks John!

Do you happen to know what the message "Next free cluster in FSInfo block (2) not free" means? Was it serious, and is fixed now? Or didn't it matter much?


----------



## Carpetsmoker (May 31, 2010)

sverreh said:
			
		

> Do you mean:
> `$ xterm -en UTF-8`
> 
> I tried this, with the same negative result. I also tried
> ...



~/.Xdefaults

```
! Use UTF-8
Xterm*locale: UTF-8

! Set (big) UTF-8 fonts.
*VT100.font:   -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1
```

Reload with `% xrdb ~/.Xdefaults`

Environment:
`% setenv LC_CTYPE en_US.UTF-8`

I suspect this is a multibyte UTF8 character ...

Regardless, tab completion in TCSH should expand & delete it.


----------



## sverreh (May 31, 2010)

@Carpetsmoker: O.K. I will try those settings tomorrow. No more time for fiddling today.


----------



## john_doe (May 31, 2010)

sverreh said:
			
		

> But I still can't delete this little bugger! Thanks John!


Does same error "Invalid argument" still appear when using ls(1) and find(1)? Listing directory contents shouldn't usually fail with any other error than "Permission denied".


----------



## vrachil (Jun 1, 2010)

I've seen that behaviour on some non-UTF8 filenames, because i didn't have the locale set as I was supposed to.
does
[CMD="echo"]*[/CMD]
print the filename?

if it is the only file in the directory, try
[CMD="rm"]-rf DIR[/CMD]


----------



## sverreh (Jun 1, 2010)

john_doe said:
			
		

> Does same error "Invalid argument" still appear when using ls(1) and find(1)? Listing directory contents shouldn't usually fail with any other error than "Permission denied".



No change: `$ ls` lists the file without problems, while `$ ls -l` fails.


```
% ls
Vivian?3
% ls -l
ls: Vivian?3: Invalid argument
total 0
% find . -name Viv\*
find: ./Vivian?3: Invalid argument
%
```


----------



## sverreh (Jun 1, 2010)

vrachil said:
			
		

> does
> [CMD="echo"]*[/CMD]
> print the filename?




```
% echo *
echo: No match.
%
```



			
				vrachil said:
			
		

> if it is the only file in the directory, try
> [CMD="rm"]-rf DIR[/CMD]


Yes, it is the only file left in the directory, so I moved to the parent directory and tried.

```
% cd ..
% ls
DCIM            MISC            PRIVATE         Pictures        Skole
% rm -rf Pictures
rm: Pictures: Directory not empty
%
```

Good idea, but same negative result. Thanks for trying!


----------



## Beastie (Jun 1, 2010)

Can you access a machine with Windows installed? You could try to run *chkdsk /f* on the disk.


----------



## magickan (Jun 1, 2010)

hmm, any idea how the file came to exist?

you could try removing the file via inode?

eg


```
ls -i test
426532045 test
```


```
find . -inum 426532045 -exec rm -i {} \;
```

this has worked for me previously on linux assume it will work on freebsd also?


----------



## OH (Jun 1, 2010)

I'll throw a stick at this.

What if you try quoting the file to be deleleted
`$ rm -f "Vivian?3"`

Or, if it's the shell misinterpreting the symbol, try a different shell. There are multiple options usually available without installing anything new (sh/csh) and some more options in /usr/ports/shells


----------



## vrachil (Jun 1, 2010)

maybe try using quotes with find?


```
find . -name "Viv*" -exec rm -i {}\;
```
also, the inode idea seems smart enough to work


----------



## sverreh (Jun 1, 2010)

Carpetsmoker said:
			
		

> ~/.Xdefaults
> 
> ```
> ! Use UTF-8
> ...



I wrote the file .Xdefaults in my home directory. Here is what it looks like:

```
% cat .Xdefaults
! Use UTF-8
Xterm*locale: UTF-8
!
! Set (big) UTF-8 fonts.
*VT100.font:   -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1
%
```
Then did the reload according to your instructions, and set the environment variable.

```
% printenv LC_CTYPE
en_US.UTF-8
%
```
The file still refuses to disappear! I type: 
	
	



```
% rm -f V
```
 and hit the Tab key. The file name is expanded to 
	
	



```
rm -f Vivian\?3
```
 and when I press return the following, now familiar, message shows up again:
	
	



```
rm: Vivian?3: Invalid argument
```

The same with 

`$ ls -l`

 and

`$ find` 

This is getting interesting!


----------



## mdhughes (Jun 1, 2010)

Have you tried doing an ls -B to get the special characters that are in the file name?


----------



## sverreh (Jun 1, 2010)

Beastie said:
			
		

> Can you access a machine with Windows installed? You could try to run *chkdsk /f* on the disk.



Yes, I have access to Windows. What does this command do?

Anyway, I would rather like to find a way of doing this in FreeBSD. This file is not a big problem for me, it occupies less than 1 MB out of the 4 GB on the card. And if I really get desperate I guess I can insert it in the Macbook again and delete it from there. So this is more like solving a puzzle and see what I can learn of new things. Before I ended up with this file I thought I knew everything there was to know about removing strange files from disk. How wrong I was! :O



			
				magickan said:
			
		

> hmm, any idea how the file came to exist?
> 
> you could try removing the file via inode?
> 
> ...



From the name of the file I would guess it contains a picture of my son's girlfriend. (Sorry guys, I can't upload it before somebody finds a way to access it! :e) He had some problems with his Macbook, and I took a backup to a flash card that I normally use in my camera.

Your proposed solution *should* work, but it doesn't. fronclynne proposed more or less the same in an earlier post, and the result is still negative:


```
% ls -i
ls: Vivian?3: Invalid argument
%
```



			
				OH said:
			
		

> What if you try quoting the file to be deleleted
> $ rm -f "Vivian?3"



Have tried several ways of quoting, so why not this one?

```
% rm -f "Vivian?3"
rm: Vivian?3: Invalid argument
%
```
I have tried Bourne shell to, same miserable result.



			
				vrachil said:
			
		

> maybe try using quotes with find?
> 
> find . -name "Viv*" -exec rm -i {}\;
> also, the inode idea seems smart enough to work



Yes, the inode idea is smart, but the command never gets that far:


```
% find . -name "Viv*" -exec rm -i {} \;
find: ./Vivian?3: Invalid argument
%
```

Thank you guys for taking part in this interesting problem!


----------



## sverreh (Jun 1, 2010)

mdhughes said:
			
		

> Have you tried doing an ls -B to get the special characters that are in the file name?



No, never thought about that. After reading through the manpage for ls I also tried the -b option. But alas:


```
% ls -B
Vivian?3
% ls -b
Vivian?3
%
```

So the file definitely does not want to give up its secrets!


----------



## Carpetsmoker (Jun 1, 2010)

How about `% ls | hd`


----------



## Beastie (Jun 1, 2010)

sverreh said:
			
		

> What does this command do?
> 
> Anyway, I would rather like to find a way of doing this in FreeBSD.


Like the name suggests, it checks disks. It replaces the old scandisk from Windows 9x (even though chkdsk already existed back then). The /f switch fixes the errors it finds.
I suggested this because when you have a problem with a product designed by Microsoft (i.e. the FAT filesystem), I think it's always better to try to fix it using _their_ tools, especially when you can't seem to be able to fix it otherwise.




			
				sverreh said:
			
		

> And if I really get desperate I guess I can insert it in the Macbook again and delete it from there.


Which will probably not work any better. After all _it_ caused the problem in the first place. But it's just a guess, don't quote me.


----------



## sverreh (Jun 1, 2010)

Carpetsmoker said:
			
		

> How about `% ls | hd`



Another original idea! You guys are bright!
This one gives some output, but I need some help to find out if it helps. I am far outside my comfort zone now. :h 

Here we go:

```
% ls|hd
00000000  56 69 76 69 61 6e 3f 33  0a                       |Vivian?3.|
00000009
%
```

As far as I can see from the manpage of hd, this is some kind of hexadecimal representation of the file name. Help to decode this will be appreciated!


----------



## sverreh (Jun 1, 2010)

Beastie said:
			
		

> Like the name suggests, it checks disks. It replaces the old scandisk from Windows 9x (even though chkdsk already existed back then). The /f switch fixes the errors it finds.
> I suggested this because when you have a problem with a product designed by Microsoft (i.e. the FAT filesystem), I think it's always better to try to fix it using _their_ tools, especially when you can't seem to be able to fix it otherwise.
> 
> 
> ...



Thanks Beastie! I kind of suspected it had something to with checking the disk. 
I think the arguments of letting windows fix windows errors is a good one, so I will try it out tomorrow. And I will test it in the Macbook tonight. And I won't quote you. (Not more than the above quote, anyway.)


----------



## sverreh (Jun 1, 2010)

I put the card into the Macbook, and had no problems reading it. It turns out the file is actually a directory with several files in it. Its name is Vivian<3. I was told by the owner that <3 is kind of a smiley for a heart: Just tilt your head 90 degrees to the right, and you will see it! Those stupid young fools. :\ 

Anyway, I guess our more or less fancy commands to delete the file try to read input from the file called "3", which does not exist. Right?

The bad news is that even though I know the "mysterious" character in the name, I'm still not able to delete it. Tried several variations with backslashes, single and double quotes with rm, rmdir, ls and find without result.

Anyone?


----------



## magickan (Jun 1, 2010)

does 


ls -i ../* produce the inode number?


----------



## jb_fvwm2 (Jun 1, 2010)

Just guessing, but if you know it is a directory,
can you not cd *into* it, move files out of it,
then change back:

```
cd ..
/bin/rm -rf "tab" (or something that will work)
```


----------



## sverreh (Jun 1, 2010)

magickan said:
			
		

> does
> 
> 
> ls -i ../* produce the inode number?



let's see:


```
sverre % ls -i ../*
../DCIM:
146432 101_PANA

../MISC:

../PRIVATE:
135168 AVCHD

../Pictures:
ls: Vivian?3: Invalid argument

../Skole:
205824 Hakadal  650240 VGS
sverre %
```

So, unfortunately, the answer is no.


----------



## sverreh (Jun 1, 2010)

jb_fvwm2 said:
			
		

> Just guessing, but if you know it is a directory,
> can you not cd *into* it, move files out of it,
> then change back:
> 
> ...



Sorry, did 
	
	



```
cd ..
```

followed by


```
sverre % /bin/rm -rf Pic
```
 and then hit Tab to get


```
sverre % /bin/rm -rf Pictures/
```

and then hit Return to get


```
sverre % /bin/rm -rf Pictures/
rm: Pictures/: Directory not empty
sverre %
```

The problem is I can't move this file, because I always get this "Invalid argument".
And I can't move into the directory for the same reason.
Nice try, though.


----------



## graudeejs (Jun 2, 2010)

sverreh said:
			
		

> Another original idea! You guys are bright!
> This one gives some output, but I need some help to find out if it helps. I am far outside my comfort zone now. :h
> 
> Here we go:
> ...



I have way better suggesting
run hd on that directory

I created sample directory X in my /tmp and did `# touch Vivian?3`
after that 
	
	



```
$ hd /tmp/x
00000000  01 14 01 00 0c 00 04 01  2e 00 00 00 02 00 00 00  |................|
00000010  0c 00 04 02 2e 2e 00 00  02 14 01 00 e8 01 08 08  |................|
00000020  56 69 76 69 61 6e [color="Red"]3f[/color] 33  00 aa 85 a0 00 00 00 00  |Vivian[color="Red"]?[/color]3........|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200
```

I think this will be more precise (in case ls interpreted your weird letter as ?)

also did you run that fsck?


BTW this file, that I created I could remove easily `$ rm Vivian\?3`


----------



## kdemidofff (Jun 2, 2010)

use KISS principle and use misc/mc port to delete it?
 xD


----------



## fronclynne (Jun 2, 2010)

copy or tar(1) everything else on the drive, format the drive, put everything else back.


----------



## pprocacci (Jun 2, 2010)

As killasmurf suggested, an fsck will most likely find and fix the problem.  Normally I'd go on to suggest running a utility that doesn't depend on the shell globbing characters and whatnot but "rf -rf dir" would cover that.  Do yourself a favor and fsck the drive.


----------



## sverreh (Jun 2, 2010)

killasmurf86 said:
			
		

> I have way better suggesting
> run hd on that directory
> 
> I created sample directory X in my /tmp and did `# touch Vivian?3`
> ...



Here is my output:


```
/% hd Pictures/
00000000  2e 20 20 20 20 20 20 20  20 20 20 30 00 80 01 97  |.          0....|
00000010  b9 3c 21 00 00 00 fd 9e  c1 3c 2f 00 00 00 00 00  |.<!......</.....|
00000020  2e 2e 20 20 20 20 20 20  20 20 20 10 00 80 01 97  |..         .....|
00000030  b9 3c b9 3c 00 00 01 97  b9 3c 00 00 00 00 00 00  |.<.<.....<......|
00000040  e5 2e 00 44 00 53 00 5f  00 53 00 0f 00 cd 74 00  |...D.S._.S....t.|
00000050  6f 00 72 00 65 00 00 00  ff ff 00 00 ff ff ff ff  |o.r.e...........|
00000060  e5 53 5f 53 54 4f 7e 31  20 20 20 22 00 8e f3 9e  |.S_STO~1   "....|
00000070  c1 3c c1 3c 00 00 f3 9e  c1 3c 14 00 04 18 00 00  |.<.<.....<......|
00000080  e5 2e 00 5f 00 2e 00 44  00 53 00 0f 00 a7 5f 00  |..._...D.S...._.|
00000090  53 00 74 00 6f 00 72 00  65 00 00 00 00 00 ff ff  |S.t.o.r.e.......|
000000a0  e5 7e 31 20 20 20 20 20  44 53 5f 22 00 af 01 97  |.~1     DS_"....|
000000b0  b9 3c b9 3c 00 00 01 97  b9 3c 30 00 52 00 00 00  |.<.<.....<0.R...|
000000c0  e5 2e 00 6c 00 6f 00 63  00 61 00 0f 00 f7 6c 00  |...l.o.c.a....l.|
000000d0  69 00 7a 00 65 00 64 00  00 00 00 00 ff ff ff ff  |i.z.e.d.........|
000000e0  e5 4f 43 41 4c 49 7e 31  20 20 20 22 00 b2 01 97  |.OCALI~1   "....|
000000f0  b9 3c ba 3c 00 00 89 75  e7 36 00 00 00 00 00 00  |.<.<...u.6......|
00000100  e5 53 43 30 30 34 38 34  4a 50 47 20 00 b3 01 97  |.SC00484JPG ....|
00000110  b9 3c bb 3c 00 00 f8 8a  3a 3a f1 06 13 0a 04 00  |.<.<....::......|
00000120  e5 53 43 30 30 34 38 36  4a 50 47 20 00 b7 01 97  |.SC00486JPG ....|
00000130  b9 3c bb 3c 00 00 a1 9a  3d 3a fa 06 7f d5 03 00  |.<.<....=:......|
00000140  e5 46 00 61 00 6c 00 6c  00 73 00 0f 00 b0 6b 00  |.F.a.l.l.s....k.|
00000150  6a 00 65 00 72 00 6d 00  00 00 00 00 ff ff ff ff  |j.e.r.m.........|
00000160  e5 41 4c 4c 53 4b 7e 31  20 20 20 10 00 ba 01 97  |.ALLSK~1   .....|
00000170  b9 3c b9 3c 00 00 01 97  b9 3c 02 07 00 00 00 00  |.<.<.....<......|
00000180  e5 79 00 00 00 ff ff ff  ff ff ff 0f 00 63 ff ff  |.y...........c..|
00000190  ff ff ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
000001a0  e5 69 00 50 00 68 00 6f  00 74 00 0f 00 63 6f 00  |.i.P.h.o.t...co.|
000001b0  20 00 4c 00 69 00 62 00  72 00 00 00 61 00 72 00  | .L.i.b.r...a.r.|
000001c0  e5 50 48 4f 54 4f 7e 31  20 20 20 10 00 4f 0f 97  |.PHOTO~1   ..O..|
000001d0  b9 3c b9 3c 00 00 0f 97  b9 3c 5b 0f 00 00 00 00  |.<.<.....<[.....|
000001e0  e5 50 00 68 00 6f 00 74  00 6f 00 0f 00 73 20 00  |.P.h.o.t.o...s .|
000001f0  42 00 6f 00 6f 00 74 00  68 00 00 00 00 00 ff ff  |B.o.o.t.h.......|
00000200  e5 48 4f 54 4f 42 7e 31  20 20 20 10 00 99 2f 98  |.HOTOB~1   .../.|
00000210  b9 3c b9 3c 01 00 2f 98  b9 3c b2 6b 00 00 00 00  |.<.<../..<.k....|
00000220  e5 53 00 70 00 61 00 6e  00 69 00 0f 00 3f 61 00  |.S.p.a.n.i...?a.|
00000230  00 00 ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
00000240  e5 50 41 4e 49 41 20 20  20 20 20 10 00 a4 2f 98  |.PANIA     .../.|
00000250  b9 3c b9 3c 01 00 2f 98  b9 3c b4 6b 00 00 00 00  |.<.<../..<.k....|
[color="red"]00000260  41 56 00 69 00 76 00 69  00 61 00 0f 00 bc 6e 00  |AV.i.v.i.a....n.|
00000270  23 f0 33 00 00 00 ff ff  ff ff 00 00 ff ff ff ff  |#.3.............|[/color]
00000280  56 49 56 49 41 4e 7e 31  20 20 20 10 00 a1 30 98  |VIVIAN~1   ...0.|
00000290  b9 3c b9 3c 01 00 30 98  b9 3c 79 6e 00 00 00 00  |.<.<..0..<yn....|
000002a0  e5 74 00 65 00 72 00 00  00 ff ff 0f 00 8e ff ff  |.t.e.r..........|
000002b0  ff ff ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
000002c0  e5 20 00 56 00 69 00 64  00 65 00 0f 00 8e 6f 00  |. .V.i.d.e....o.|
000002d0  20 00 43 00 6f 00 6e 00  76 00 00 00 65 00 72 00  | .C.o.n.v...e.r.|
000002e0  e5 58 00 69 00 6c 00 69  00 73 00 0f 00 8e 6f 00  |.X.i.l.i.s....o.|
000002f0  66 00 74 00 20 00 69 00  50 00 00 00 6f 00 64 00  |f.t. .i.P...o.d.|
00000300  e5 49 4c 49 53 4f 7e 31  20 20 20 10 00 43 31 98  |.ILISO~1   ..C1.|
00000310  b9 3c b9 3c 01 00 31 98  b9 3c 5d 6f 00 00 00 00  |.<.<..1..<]o....|
00000320  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00008000
/%
```

Nice idea that gave new information, killasmurf!

From a table of extended ASCII-codes, this is what I find the file name to be:

V NUL i NUL v NUL i NUL a NUL Shift-in NUL 1/4 n NUL ETB small-eth 3

and (possibly) a capital A in the front. I have no idea how I can address this directory. Is it possible to give a file name as octal or hex codes to commands? I mean, is there a way of typing something like


```
rm -r \xxx\yyy\zzz
```

such that rm will see the file?

Yes, i did fsck the card, see post #21


----------



## nekoexmachina (Jun 2, 2010)

There was pretty same problem for me (and konqueror could not show the file too), when i've forgot to set up locales and tried to operate with partially non-ascii named file.



> rm -r \xxx\yyy\zzz


It should work. At least as i remember i could open my wrong-encoding-named file with that.
upd: Oh wait, if it IS msdosfs, than no, you can't. 
also try viewing man mount_msdosfs for -L and some another encoding option. You need to use both for mounting (e.g. one to decode from msdos-encoding, another to encode to your locale encoding)
Hope that will help.


----------



## graudeejs (Jun 2, 2010)

My best bet would be to try to write perl script, that would remove this file


----------



## graudeejs (Jun 2, 2010)

try something like this

```
#!/usr/bin/perl
unlink "\x{4156}\x{0069}\x{0076}\x{0069}\x{0061}\x{000f}\x{00bc}\x{6e00}\x{23f0}\x{3300}";
```


----------



## graudeejs (Jun 2, 2010)

or

```
#!/usr/bin/perl
opendir(CURRENT_DIR, ".") or die "ERR: can't read dircetory: '$item'.\n$1\n";
my @content = readdir CURRENT_DIR;
closedir(CURRENT_DIR);
foreach my $i (2 .. $#content) {
  unlink $i if ($i ~= m/\x{4156}\x{0069}\x{0076}.*/);
}
```
or more brutal:

```
#!/usr/bin/perl
opendir(CURRENT_DIR, ".") or die "ERR: can't read dircetory: '$item'.\n$1\n";
my @content = readdir CURRENT_DIR;
closedir(CURRENT_DIR);
foreach my $i (2 .. $#content) {
  unlink $i or warn "WARN: Unable to rm $i";
}
```
be sure to backup data, as I haven't tested this script [should work however]
and execute in same dir as that file

another crazy idea: [not sure if hex editor will allow you to, but worth trying. Folders are basically files. Actually everything is file in unix]:
using some hex editor and simply open folder as with hd, and edit filename to common sense (should end with 0), But be extra careful


----------



## sverreh (Jun 2, 2010)

kdulep said:
			
		

> use KISS principle and use misc/mc port to delete it?
> xD



That may work. However, I already tried konqueror as file manager, and it does not see the file at all. Anyway, I installed mc, although not very successfully:


```
~ % mc
/libexec/ld-elf.so.1: /usr/local/bin/mc: Undefined symbol "g_malloc0_n"
```

I probably need to update my ports, but am reluctant to do that now after having been bitten by the jpeg update earlier this year. My machine was compiling for 3 days. x(

Thanks for the idea anyway!



			
				fronclynne said:
			
		

> copy or tar(1) everything else on the drive, format the drive, put everything else back.



That's probably what I will end up doing. Very drastic, but sure to get rid of the junk.
Thanks.



			
				pprocacci said:
			
		

> As killasmurf suggested, an fsck will most likely find and fix the problem. Normally I'd go on to suggest running a utility that doesn't depend on the shell globbing characters and whatnot but "rf -rf dir" would cover that. Do yourself a favor and fsck the drive.



I already did fsck, see results in post #21. What I haven't done yet is to use chkdsk /f on a Windows machine, as proposed by Beastie in post #28. Will try do do that today.


----------



## Beastie (Jun 2, 2010)

When you said in post #40 that you're still unable to remove the directory, does this include using the MacBook too?

On what OS was the directory first created? MacOS? Because using these characters -- *" * / : < > ? \ |* -- in a FAT filesystem is forbidden.


----------



## magickan (Jun 2, 2010)

hi

another way to find the inode is 


```
find . -ls

3988944        0 drwxr-xr-x    3 adz      staff         102  1 Jun 20:46 .
3988947        0 -rw-r--r--    1 adz      staff           0  1 Jun 20:46 ./test
```

where the inode is the number on the left.  with regard to the ls -i command whats happening is that the ls cant process the input, but maybe find can?

/mgk


----------



## pprocacci (Jun 3, 2010)

You may have luck using fsdb.  Be very wary though, this utility has the opportunity of screwing things up royally.  Do NOT mount the partition you want to work on....then:

Example:

```
fsdb /dev/ad0s1e   # Use your device
Last Mounted on /tmp
current inode: directory
I=2 MODE=41777 SIZE=1024
        BTIME=May  1 01:53:23 2009 [0 nsec]
        MTIME=Jun  2 18:46:29 2010 [0 nsec]
        CTIME=Jun  2 18:46:29 2010 [0 nsec]
        ATIME=Jun  2 18:48:46 2010 [0 nsec]
OWNER=root GRP=wheel LINKCNT=24 FLAGS=0 BLKCNT=4 GEN=38b32c1c
fsdb (inum: 2)> cd x
component `x': current inode: directory
I=16452 MODE=40755 SIZE=512
        BTIME=Jun  2 18:46:28 2010 [0 nsec]
        MTIME=Jun  2 18:46:38 2010 [0 nsec]
        CTIME=Jun  2 18:46:38 2010 [0 nsec]
        ATIME=Jun  2 18:47:53 2010 [0 nsec]
OWNER=root GRP=wheel LINKCNT=2 FLAGS=0 BLKCNT=4 GEN=fffffffff75b9986
fsdb (inum: 16452)> ls
slot 0 ino 16452 reclen 12: directory, `.'
slot 1 ino 2 reclen 12: directory, `..'
slot 2 ino 16457 reclen 488: regular, `Bla?h'
fsdb (inum: 16452)> clri 16457
fsdb (inum: 16452)> exit
```

Run:

`fsck -y /dev/ad0s1e   # or your device`

Then mount.

Just a word of caution though, I've done this once before in the past, but don't remember if anything else needs to be done.  fsdb did save my ass the one time however.

Edit:  If that doesn't work, you can try removing the parent inode using the above as well, followed by an fsck.
Edit2: I honestly don't think the perl approach will work, but please try and let us know.


----------



## expl (Jun 3, 2010)

Compile this `cc -o rfiles sourcefile.c`
Run `./rfiles /your/path`


```
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <assert.h>

/*Usage: app [path]*/

int main(int argc, char **argv){
	DIR *dir_h;
	struct dirent *dirn;
	char *path = NULL;
	
	if(argc == 1)
		return 1;
	
	if((dir_h = opendir(argv[1])) == NULL){
		perror("Error:");
		
		return 1;
	}
	
	while((dirn = readdir(dir_h)) != NULL){
		if(dirn->d_type != DT_DIR){
			asprintf(&path, "%s/%s", argv[1], dirn->d_name);
			assert(path != NULL);
			
			printf("Deleting '%s'.", path);
			
			if(remove(path) == -1){
				perror("\nError:");
			} else
				printf(" Done!\n");
			
			free(path);
		}
	}
	
	closedir(dir_h);
	
	return 0;	
}
```

If this fails its problem at the mount_msfs module.


----------



## sverreh (Jun 3, 2010)

killasmurf86 said:
			
		

> or
> 
> ```
> #!/usr/bin/perl
> ...



Sorry for this late answer, but occasionally I am required to do some useful work during the day. Killasmurf, you are incredible! When I read your post suggesting a perl script, I turned around to grab my Camel and Cokbook from the bookshelf. When I turned back, you had already supplied three scripts. (Well, almost  )

I copied your first script to file ~/viv_del.pl and did:


```
% ~/viv_del.pl
% ls
Vivian?3
```

Still there!

when inspecting your script I got the idea that maybe the A (41) should not be part of the name, so I modified the script and called it ~/viv_del1.pl:


```
% sdiff ~/viv_del.pl ~/viv_del1.pl
#!/usr/bin/perl                                                 #!/usr/bin/perl
unlink "\x{4156}\x{0069}\x{0076}\x{0069}\x{0061}\x{000f}\x{00 | unlink "\x{5600}\x{6900}\x{7600}\x{6900}\x{6100}\x{0f00}\x{bc
```


```
% ~/viv_del1.pl
% ls
Vivian?3
```

No luck!

Copied your second script to ~/viv_del2.pl after correcting a small typo (~= should be =~):


```
% ~/viv_del2.pl
% ls
Vivian?3
```

Copied your third script to ~/viv_del3.pl:


```
% ~/viv_del3.pl
WARN: Unable to rm 2 at /home/sverreh/viv_del3.pl line 6.
```

Modified the script and saved it in ~/viv_del4.pl:


```
% sdiff -sw 155 ~/viv_del3.pl ~/viv_del4.pl
   unlink $i or warn "WARN: Unable to rm $i";  |  unlink [color="red"]$content[$i][/color] or warn "WARN: Unable to rm [color="red"]$content[$i][/color]";
```


```
~/viv_del4.pl
WARN: Unable to rm Vivian?3 at /home/sverreh/viv_del4.pl line 6.
```

So we are out of luck again! 

The idea with the hex editor is interesting, so I tried with hexedit:

First, I changed to the parent directory:


```
% cd ..
% ls -l
total 160
drwxr-xr-x  1 sverreh  wheel  32768 May 27 22:22 DCIM
drwxr-xr-x  1 sverreh  wheel  32768 May 27 22:22 MISC
drwxr-xr-x  1 sverreh  wheel  32768 May 28 21:03 PRIVATE
drwxr-xr-x  1 sverreh  wheel  32768 Jun  1 21:55 Pictures
drwxr-xr-x  1 sverreh  wheel  32768 May  4 14:13 Skole
```

and then 


```
% hexedit Pictures
hexedit: Pictures: Not a file.
```

So your suspicion was right. However I know that vim can read directories, and tried the following:


```
% vim Pictures/
```

which gave me the following display:


```
" ============================================================================
" Netrw Directory Listing                                        (netrw v132)
"   /a/pictures
"   Sorted by      name
"   Sort sequence: [\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:exec
" ============================================================================
../
.swp*
```

So vim doesn't see Vivian?3 either!


----------



## sverreh (Jun 3, 2010)

Beastie said:
			
		

> When you said in post #40 that you're still unable to remove the directory, does this include using the MacBook too?
> 
> On what OS was the directory first created? MacOS? Because using these characters -- *" * / : < > ? \ |* -- in a FAT filesystem is forbidden.



No, it does not include the MacBook. There the directory and files seem to be O.K., so I guess deleting it would be no problem. But that would of course take the fun out of this project!

The directory was copied from the Macbook originally.



			
				magickan said:
			
		

> another way to find the inode is
> 
> 
> ```
> ...



Thanks for the idea! I wasn't aware of this possibility in find. But it didn't solve the problem:


```
% find . -ls
177152       64 drwxr-xr-x    1 sverreh          wheel               32768 Jun  1 21:55 .
find: ./Vivian?3: Invalid argument
```

@ pprocacci and @ expl:

I will need some more time to look into your proposals. Be patient!


----------



## graudeejs (Jun 3, 2010)

sverreh said:
			
		

> Sorry for this late answer, but occasionally I am required to do some useful work during the day. Killasmurf, you are incredible! When I read your post suggesting a perl script, I turned around to grab my Camel and Cokbook from the bookshelf. When I turned back, you had already supplied three scripts. (Well, almost  )


:r



			
				sverreh said:
			
		

> The idea with the hex editor is interesting, so I tried with hexedit:
> 
> First, I changed to the parent directory:
> 
> ...



I tried bunch of editors, and those that opened directory refused to save modified data  [Well I expected that]

Now I have *The Most Perverse Idea Ever*, I doubt anyone will beat me on this one.
We know file name pattern
could open up hex editor, and edit unmounted device directly.
First you need to find file name patern [you don't need to be limited to fine name only, you dumped much more data in previous post], then verify that it is the one. [Shouldn't be too hard, because you can search quite a big pattern] and then modify filename to common sense 

This is of course brutal force, brutal stupidity, brutal [your word here], and you risk damaging your file system [but this might be fun]

i think editors/hte will suit this purpose best [it installs binary named *ht*]


----------



## kdemidofff (Jun 3, 2010)

just do newfs already and stop this spam


----------



## Beastie (Jun 3, 2010)

killasmurf86 said:
			
		

> Now I have *The Most Perverse Idea Ever*, I doubt anyone will beat me on this one.


Don't you wish!



			
				killasmurf86 said:
			
		

> This is of course brutal force, brutal stupidity, brutal [your word here], and you risk damaging your file system


Yeah, all the above... if you don't know what you're doing, muhahaha.



			
				killasmurf86 said:
			
		

> i think editors/hte will suit this purpose best


My favorite choice too. 





			
				kdulep said:
			
		

> just do newfs already and stop this spam


LOL


----------



## Carpetsmoker (Jun 3, 2010)

If a directory is displayed as a file then this would indicate the filesystem is damaged.
You already ran fsck_msdosfs, and MacOS X can read the card properly, so either MacOS is doing something strange, or something is damaged (And MacOS X can read it anyway).

The strange name is a symptom of the same problem, not the cause.


----------



## sverreh (Jun 7, 2010)

expl said:
			
		

> Compile this `cc -o rfiles sourcefile.c`
> Run `./rfiles /your/path`



I compiled it as instructed and did:


```
% ~/rfiles .
 % ls
Vivian?3
```

I think the problem is that your program deletes normal files, but not directories. And the Vivian?3 is a directory, as shown by the Macbook. To test this, I created two directories and populated them with two files in each:


```
% mkdir -p try/try1
% touch try/{f1,f2,try1/{f3,f4}}
% ls try
f1      f2      try1
% ls try/try1
f3      f4
```

Then I ran rfiles again, and checked the files:

```
% ~/rfiles .
% ls
Vivian?3        try
% ls try
f1      f2      try1
```

So all the files are still there. I then changed to directory try and re-ran rfiles:


```
% cd try
% ~/rfiles .
Deleting './f1'. Done!
Deleting './f2'. Done!
% ls
try1
% ls try1
f3      f4
```

Works perfectly for the normal files, but leaves directory try1 intact. If I were an expert in C (like you seem to be) I could have tried to modify your program to delete directories, but I am not fluent in that language! (very far from, in fact).

Very nice try, thanks a lot for your time and effort!


----------



## sverreh (Jun 7, 2010)

pprocacci said:
			
		

> You may have luck using fsdb.  Be very wary though, this utility has the opportunity of screwing things up royally.  Do NOT mount the partition you want to work on....then:



After studying manpages for a long time, I jumped into it:


```
# fsdb /dev/da0s1
** /dev/da0s1
Cannot find file system superblock
ioctl (GCINFO): Inappropriate ioctl for device
fsdb: /dev/da0s1: can't read disk label
#
```

So, no luck!



			
				pprocacci said:
			
		

> Edit2: I honestly don't think the perl approach will work, but please try and let us know.



As reported in my reply to killasmurf, you are right. Thank you, pprocacci


----------



## sverreh (Jun 7, 2010)

Carpetsmoker said:
			
		

> If a directory is displayed as a file then this would indicate the filesystem is damaged.
> You already ran fsck_msdosfs, and MacOS X can read the card properly, so either MacOS is doing something strange, or something is damaged (And MacOS X can read it anyway).
> 
> The strange name is a symptom of the same problem, not the cause.



Could you elaborate a bit on this, Carpetsmoker? The file is displayed with ls, but isn't that normal behaviour  even for directories? 


```
ls -l
```
does not list the directory as a file, it just reports "invalid argument".


----------



## Beastie (Jun 7, 2010)

sverreh said:
			
		

> ```
> # fsdb /dev/da0s1
> ** /dev/da0s1
> Cannot find file system superblock
> ...


fsdb(8) works on FFS (Fast File System) AKA UFS.

A FAT filesystem has a BIOS Parameter Block, FAT cluster linked lists, and a root directory in the data area (for FAT32). A UFS filesystem has bootblocks, a superblock, and cylinder groups with inode tables and free block bitmaps.
In other words, they are fundamentally different filesystems based on fundamentally different concepts.





			
				sverreh said:
			
		

> Could you elaborate a bit on this, Carpetsmoker? The file is displayed with ls, but isn't that normal behaviour  even for directories?
> 
> 
> ```
> ...


The problem is very simple as you found out many posts ago: FreeBSD is confused by the redirection *<* character. It's 100% MacOS's fault. It should never accept a *<* character on a FAT filesystem to begin with.


----------



## fronclynne (Jun 7, 2010)

Beastie said:
			
		

> fsdb(8) works on FFS (Fast File System) AKA UFS.
> 
> A FAT filesystem has a BIOS Parameter Block, FAT cluster linked lists, and a root directory in the data area (for FAT32). A UFS filesystem has bootblocks, a superblock, and cylinder groups with inode tables and free block bitmaps.
> In other words, they are fundamentally different filesystems based on fundamentally different concepts.
> ...



I hadn't realised, when I offered fsdb, that he was working with FAT32, so I apologise for leading astray.


Another option would be to hack up a shell that doesn't use [red]<[/red] as a redirect.  I doubt that's a trivial exercise, though.  I'm also not sure about the actual commands like ls(1), do they parse redirections that aren't intercepted by the shell?


----------



## hector (May 10, 2012)

I had a similar problem but the name of the file started with a dash "--filename".

The problem:
[cmd=]# rm "--filename"[/cmd]

```
rm: illegal option -- -
usage: rm [-f | -i] [-dIPRrvW] file ...
       unlink file
```

Then I found this and it worked:
`# rm ./--filename`


----------



## SirDice (May 10, 2012)

This also works:
`$ rm -- --filename`

The -- will tell rm(1) there are no more options and everything else should be treated as a filename.


----------



## Carpetsmoker (May 13, 2012)

SirDice said:
			
		

> This also works:
> `$ rm -- --filename`
> 
> The -- will tell rm(1) there are no more options and everything else should be treated as a filename.



To slightly expand on this, using -- is a getopt(3) feature, not a rm-specific feature. From getopt(3):


```
The interpretation of options in the argument list may be cancelled by
     the option â€˜--â€™ (double dash) which causes getopt() to signal the end of
     argument processing and return -1.
```


----------



## SirDice (May 14, 2012)

Yes, basically that means you can use that trick with other commands too.


----------



## y2s82 (Jun 12, 2012)

*awww*

While searching for answers for a slightly different question, I stumbled on this subject.  I had wondered about this for yet another problem I have for some other folder and was reading with enthusiasm as each potential solution was proposed and tried.  I guess this never concluded, not using FreeBSD anyways.

My trouble is that the file name contains a Korean character copied over from Windows system.  My system reads Korean in UTF8 just fine, but can't read that particular character and displays it in ? mark. (e.g. "imageìž¬1.jpg" would show up as "image?1.jpg") It wouldn't be deleted or moved or accessed in ordinary ways (haven't tried any of the above-mentioned scripts or other scary looking methods).  My guess is that it's encoded in UTF-16 or something.  Does anyone have any update to this problem?


----------



## SirDice (Jun 12, 2012)

[cmd=]rm image*1.jpg[/cmd]


----------



## sidetone (Mar 15, 2015)

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 
	
	



```
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.


----------



## purplecat (Nov 3, 2017)

I had a file accidentally named '?'

What worked for me was:
rm ./?

within an sh shell.

Source:
https://kb.iu.edu/d/abao


----------



## SirDice (Nov 8, 2017)

purplecat said:


> 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.


```
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 ?:

```
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.


----------



## poorandunlucky (Nov 11, 2017)

And we don't even know what happened to the OP's file...


----------



## SirDice (Nov 13, 2017)

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 (Nov 13, 2017)

SirDice said:


> 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...


----------



## Lukiahas (Aug 9, 2018)

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")`


----------



## tingo (Aug 15, 2018)

I wonder why nobody mention the use of `rm -i ...`? Perhaps nobody reads the man page (rm(1))?


----------



## Eric A. Borisch (Aug 16, 2018)

tingo said:


> I wonder why nobody mention the use of `rm -i ...`? Perhaps nobody reads the man page (rm(1))?



If you can set up a find(1) query that will identify the problem directory (or file) alone, the `-delete` primary works well for files that are painful to identify from the shell.


----------



## Maelstorm (Aug 16, 2018)

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.


----------



## Nicola Mingotti (Aug 16, 2018)

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.


----------



## free-and-bsd (Aug 17, 2018)

Nicola Mingotti said:


> 1] enter the ruby REPL = > `irb`
> --> now i suppose you are in IRB REPL, you can quit with Ctrl-c


In my case only Ctrl-D worked


----------



## Nicola Mingotti (Aug 17, 2018)

free-and-bsd said:


> In my case only Ctrl-D worked


sure, quitting is the easiest part, there are more ways  also type


free-and-bsd said:


> In my case only Ctrl-D worked


sure, also giving `quit` command will work


----------



## kpa (Aug 17, 2018)

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.


----------



## free-and-bsd (Aug 17, 2018)

kpa said:


> 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_.


----------



## Nicola Mingotti (Aug 17, 2018)

kpa said:


> 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.


----------



## kpa (Aug 17, 2018)

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.


----------



## Nicola Mingotti (Aug 18, 2018)

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


----------

