The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how can i replace "(", "\" "+" in a file mail2sant Shell Programming and Scripting 3 04-22-2008 08:10 PM
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
"sed" to check file size & echo " " to destination file jockey007 Shell Programming and Scripting 6 11-13-2007 06:00 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 01:15 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-15-2003
Registered User
 

Join Date: Nov 2003
Posts: 19
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::

Last edited by oombera; 02-19-2004 at 02:34 PM.
Forum Sponsor
  #2  
Old 11-15-2003
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
Quote:
I have tried cat \-myfile with no success.
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
  #3  
Old 11-15-2003
kduffin's Avatar
UN1X
 

Join Date: Nov 2003
Location: Virginia
Posts: 441
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

Last edited by kduffin; 11-17-2003 at 07:28 PM.
  #4  
Old 11-16-2003
Registered User
 

Join Date: Nov 2003
Posts: 19
Found answer, thanks for help

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.....???
  #5  
Old 11-16-2003
kduffin's Avatar
UN1X
 

Join Date: Nov 2003
Location: Virginia
Posts: 441
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

Last edited by kduffin; 11-17-2003 at 07:28 PM.
  #6  
Old 11-17-2003
jsilva's Avatar
Registered User
 

Join Date: Apr 2003
Posts: 169
Hi,

You can do cat ./-myfile as well.
  #7  
Old 11-17-2003
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
hehe i guess no one caught onto my hint...
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0