Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When using the Bash command line I can for example change to a directory using...

cd /volumes

However I would like to type...

cd /vol*

but that doesn't work. Is there a way to navigate directories using wildcards?

share|improve this question

migrated from stackoverflow.com Jun 4 '12 at 17:31

This question came from our site for professional and enthusiast programmers.

    
It works for me –  Emil Vikström Jun 4 '12 at 16:14
    
Will you say more about what you are trying to do? What behavior do you expect when there are multiple directories matching the name /vol*? –  Adam Monsen Jun 4 '12 at 16:16
    
What would you expect cd /vol* to do? –  stakx Jun 4 '12 at 16:17
    
As an aside you could use iTerm, it's a much better alternative to the default osx terminal. iterm.sourceforge.net It allows for tab completion and the example above should work without any problems. –  에이바 Jun 4 '12 at 17:52
    
@AvaGailliot bash provides tab completion regardless of the terminal program you're running. See Gordon Davisson's answer about configuring bash to ignore case for globbing & tab completion. –  Doug Harris Jun 4 '12 at 19:01
add comment

3 Answers

up vote 4 down vote accepted

Mac OS by default uses a case insensitive file system. cd /volumes is equivalent to cd /Volumes, but bash cannot glob the vol*: try cd /Vol*

share|improve this answer
add comment

As @William Pursell said, this is due to the folder being named /Volumes, not /volumes; the OS X filesystem is case insensitive, so it ignores the difference, but bash is case sensitive and trips over the difference.

But you can change bash's default behavior: to make it do case-insensitive expansions of file patterns, add the command shopt -s nocaseglob to your ~/.bashrc and ~/.bash_profile files (it's needed in both, so the option is set in both login shells and subshells). If you also want filename completion to work despite case mismatches, either add set completion-ignore-case on to your ~/.inputrc file, or add bind "set completion-ignore-case on" to your ~/.bashrc and ~/.bash_profile files.

share|improve this answer
add comment

Typing:

cd /vol*

works just fine. Even if /vol* expands to multiple directories, bash will use the first one and ignore the rest. What exactly isn't working for you?

share|improve this answer
2  
Of course you'd normally just type cd /vol<TAB> and use auto completion... –  Paul R Jun 4 '12 at 16:24
    
@larsks I get -bash: cd: /vol*: No such file or directory when I type that in. I am using the Terminal on Mac OS. cd /volumes changes to that directory just fine. –  John Jun 4 '12 at 16:24
    
@PaulR - Using Mac OS, hitting tab doesn't complete the line for me. I have used that in the past with success on another Unix machine however. –  John Jun 4 '12 at 16:25
    
@John: must be something funny with your bash setup then - it works for me on all current/recent versions of Mac OS X - I do seem to remember that very early versions of Mac OS X needed some tweaking to make it work though. –  Paul R Jun 4 '12 at 16:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.