The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 08:23 AM
Strange error "host: isc_taskmgr_create: no available threads" Santi Linux 0 01-03-2008 02:49 AM
Listing only directories in the current working directory using the "ls" command igandu UNIX for Dummies Questions & Answers 2 05-12-2006 01:47 AM
Unix "at" / "Cron" Command New Problem...Need help Mohanraj UNIX for Dummies Questions & Answers 3 01-26-2006 05:08 PM
chmod 777 on all directories below...how do I do that using the "find" command? Neko UNIX for Dummies Questions & Answers 7 07-12-2001 06:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-06-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Question bash: cd command to access "strange" directories

I have a problem using bash. Simply, I cannot find the right command (if there's one!) to enter in the "- Arch_02 -" directory. As you can see, the name begins with a hyphen and this is causing some trouble:

Code:
localhost arch2 # pwd
/mnt/arch2
localhost arch2 # ls -l
total 4
dr-x------ 1 root root 4096 2007-04-29 20:09 - Arch_02 -
dr-x------ 1 root root    0 2006-12-10 18:14 RECYCLER
dr-x------ 1 root root    0 2006-12-02 22:24 System Volume Information

localhost arch2 # cd -\ Arch_02\ -
bash: cd: - : invalid option
cd: usage: cd [-L|-P] [dir]

localhost arch2 # cd "- Arch_02 -"
bash: cd: - : invalid option
cd: usage: cd [-L|-P] [dir]

localhost arch2 # cd '- Arch_02 -'
bash: cd: - : invalid option
cd: usage: cd [-L|-P] [dir]

localhost arch2 # cd - -\ Arch_02\ -
/root

localhost ~ # cd /mnt/arch2

localhost arch2 # cd - "- Arch_02 -"
/root

If I use csh instead, I can regularly access the directory by issuing the command:
Code:
(localhost:/mnt/arch2) # cd "- Arch_02 -"
(localhost:/mnt/arch2/- Arch_02 -) # pwd
/mnt/arch2/- Arch_02 -
With bash completion, if I press tab while typing directory's name, I can also see the subdirectories under "- Arch_02 -", but cannot access them with cd!

Does anyone have the answer?

Thanks a lot!
Reply With Quote
Forum Sponsor
  #2  
Old 07-06-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Code:
cd -- '- Arch_02 -'
Reply With Quote
  #3  
Old 07-06-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Here is how you can do it:
Code:
cd ./*Arch_02*

Last edited by Shell_Life; 07-06-2007 at 01:50 PM.
Reply With Quote
  #4  
Old 07-06-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Wow! Many many thanks! Both solutions are working great.

By the way, now that I have the answer I think I should have read more carefully the options in man bash
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:15 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