LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-28-2006, 12:40 AM   #1
bobdevis
Member
 
Registered: Nov 2006
Distribution: Ubuntu 64bit
Posts: 49

Rep: Reputation: 15
How to handle dir names starting with a '-'?


Hi all!

There is this machine on our network (that I browse with Samba) that has some directoy names names like:
-= Some Dir =-
I can browse thiese with a GUI browser. I can however not figure out how to get into them with the command line.

cd -= Some Dir =-
does not work. You get this in return:
bash: cd: -=: invalid option
cd: usage: cd [-L|-P] [dir]

cd "-= Some Dir =-" or cd '-= Some Dir =-' do not not work either. You get the same error message.

Does anyone have any idea?
Googeling this is a bit problematic, so that's why I decided to ask here.

Thanx in advance!
 
Old 11-28-2006, 01:40 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Insert a "--" flag before the folder name. 'cd -- "-somedir-"' The "--" tells the command that there are no more options and everything follows it is an argument (usually a file or folder name).

And remember, when you have "illegal" characters in a filename (including spaces), they need to be be escaped by either enclosing the whole name in quotes or by placing a backslash in front of the illegal character.

Of course, the best thing is simply to not use illegal characters in pathnames in the first place.
 
Old 11-28-2006, 01:54 AM   #3
bobdevis
Member
 
Registered: Nov 2006
Distribution: Ubuntu 64bit
Posts: 49

Original Poster
Rep: Reputation: 15
Ahhh thanx.
cd -- "-= Some Dir =-"
does the job.

The machine those dirs are on is not under my control and yes the person who came up with the bright idea to use names like that deserves spanking >:|
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to cd into dir starting with hyphen? JussiKp Linux - Newbie 2 11-05-2006 08:59 PM
how to handle file names with spaces in them bahadur Programming 14 04-04-2005 12:04 PM
how to handle file names with spaces in them bahadur Programming 3 03-23-2005 05:15 AM
Konqueror: Icons/file names don't show up for home dir jlangelier Linux - Software 3 12-10-2004 02:54 PM
Need to remove spaces from all file / dir names ?? Solution here! jsjohnst Linux - General 2 07-20-2004 09:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration