1

I cannot remove such file, I get error message. file name is

-?]d?j??.?

and I want to remove it. I try rm -?]d?j??.? but it gives error.

muru
  • 197,895
  • 55
  • 485
  • 740
  • And https://askubuntu.com/questions/278000/how-do-i-use-filenames-that-start-with-a-dash-as-command-arguments – muru Jul 06 '18 at 05:26

2 Answers2

5

According to manual,

To remove a file whose name starts with a '-', for example '-foo', use one of these commands:

rm -- -foo
rm ./-foo

In you case enter:

rm -- -?]d?j??.?

or

rm -- '-?]d?j??.?'
muru
  • 197,895
  • 55
  • 485
  • 740
2

First, look at the file with ls -b ./-* to see the real filename. You can use bash file completion to delete the file:

rm ./-

Followed by the TAB character.

Using the TAB will expand the funny characters in the filename just the way bash wants to parse them.

rm supports options, introduced by -. When it sees your filename beginning with -, it gets confused. Putting the name of the current directory ("./") in front of the filename means the same file, but the name now starts with a ., which doesn't confuse rm.

waltinator
  • 36,399