How to cat a file , name starts with "-" ?

I have a question - beginning user, just learning unix.

I have a file that name starts with a hypen -, such as a name like :

-myfile (yes, I know shold not start files names like this, but this is the question I have to figure out, and its driving me nuts)

I know that this hyphen is like a special character.. right ? So how do I cat or more this file to see its contents when it is named like this ?

I've tried commenting the hyphen, such as :

cat '-'myfile and I have tried cat \-myfile with no success.

Advice appreciated.

::email removed::

so you said that this is a question you have to figure out.... a HOMEWORK question? this is not allowed here! \-myfile...it looks like you tried to escape the '-'. your on the right track, why dont you try one more time.

/ EOF

Hey,

You need to let cat know that you aren't trying to feed it a flag. This can be done by using --

$ cat -- \-filename

Cheers,
Keith

Thanks for the help on this. I finally found ( or stumbled across) the answer by looking in the "man rm" , where it says that following the rm command with the "--" means it treats what follows that as a filename, allowing the filename to start with the hyphen.

Is the hyphen a "special character " ? I don't see it listed as such in the lists of special characters.....???

Not a special character per say, but it is what is used to identify option flags at the CLI. -- is used to denote an end of all option flags. Congrats on having found the answer yourself before hand. I have always found great satisfaction in problem solving and creative thinking. UNIX and other such appendages provide a good playground for such activities.

Cheers,
Keith

Hi,

You can do cat ./-myfile as well.

hehe i guess no one caught onto my hint...

OK....now you are making me even more curious....does your hint have something to do teith the / EOF posted at the end of your message. ?

I assume the other suggestion, using " cat ./-myfile" works because the "." indicates to do a cat on every file located in the directory, including the hidden ones.....and then the forward slash / turns off the option character - that follows...

Thanks again...

One part of his hint involved the forum rules which you have violated. Click on the rules link at the bottom of the page. Take at look at rule number 6.

I don't understand the other part of the hint myself. Backslash is the correct escape character but escaping the hyphen won't help since it's not the shell that is interpreting it specially.

OK, I understand the forum rules now, and apologize. I'm new here, and will not make that mistake again. I did end up finding the answer myself anyways before seeing the otjher posts, just had to dig deeper in another direction.

In any case, I'm intrigued by the number of different ways to perform this same operation within UNIX.....that is why I'm still trying to understand this specific topic I posted more, even though I have the answer I needed....Just seeking to learn more about it.

In any case, I've learned my lesson, not to be repeated. OK ?