plhn plhn - 4 months ago 12
Bash Question

cat `-q` file (in linux)

I have a file whose name is

-q
(It looks like this is made by accident)

I want to see it’s content, so I tried these

$ cat '-q'
$ cat "-q"
$ cat $'-q'


But nothing worked.(All gives same error
cat: invalid option -- 'q'
)

Is there any way to see it’s content?

Answer

to create a file named -q do

touch -- "-q"

and to view its contents

cat -- "-q"

should do it. -- means what follows should be treated as a positional parameter.