plhn plhn - 4 months ago 11
Linux Question

cat `-q` file (in linux) - passing operands that look like options

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' # Used single quotes to treat anything inside as literal characters

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


Pls take time to look at @rici's [ answer ] which reminds some substle aspects regarding single vs double quotes.

Comments