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?

  • 1
    It works for me 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*? 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. Jun 4 '12 at 19:01

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*


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.



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?

  • 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. 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. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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