How to delete file with this name on linux: -]???????q

15

6

Somehow a file named -]???????q got created on my terminal. I tried rm -f "-]???????q" (in double quotes), but it did not get deleted. (Error:: rm: invalid option -- ]). How do I delete it?

JP19

Posted 2011-01-06T15:40:55.767

Reputation:

Question was closed 2017-12-15T12:14:41.793

I had similar problem, in my case the problem was with samba implementation, just try to ssh to server and then remove it – Buksy – 2016-04-05T08:43:58.480

Answers

27

For example, with:

rm -- '-]???????q'

Where -- means: "stop parsing options".

cYrus

Posted 2011-01-06T15:40:55.767

Reputation: 18 102

Indeed, I ran into a similar problem not even thinking about - being a switch. I swear I spent like 2 hours trying to figure it out. – Jeff F. – 2011-01-06T17:11:03.197

Many applications use --, guess it's a kind of de facto standard due to the getopt function. – cYrus – 2011-01-06T18:42:21.390

13

You can either use the file name with rm or the inode number with find like :

rm -- -]???????q
# or
  -> ls -i                                                                                                                         
47984689 blah.ui  47983771 __init__.py  
47983773 testpy.e4p  47985161 Ui_blah.py

  -> find -inum 47983773                                                                                                           
./testpy.e4p

  -> find -maxdepth 1 -inum 47983773 -exec rm -i '{}' \;
#or
  -> find -maxdepth 1 -inum 47983773 -delete

OneOfOne

Posted 2011-01-06T15:40:55.767

Reputation: 889

Add -maxdepth 1 otherwise find will iterate through all subdirectories: find -maxdepth 1 -inum 47983773 -delete – Fabian Ritzmann – 2016-04-12T07:33:19.507

@FabianRitzmann good call, I added it. – OneOfOne – 2016-07-29T16:02:19.383

1This should be the chosen answer. Accessing file with invalid characters in its name by its iNode is the only correct way. – ScumCoder – 2018-08-28T21:59:38.830

1

rm ./"-]???????q"

Double quotes prevent the shell from expanding interrogation marks. For example, if you had another file called -]foobar.q:

$ touch ./"-]???????q" ./-]foobar.q
$ echo ./-]???????q
./-]foobar.q ./-]???????q

marco

Posted 2011-01-06T15:40:55.767

Reputation: 201

Oh. I put the quotes, but was missing the ./ – None – 2011-01-07T04:35:04.203