Why does the wildcard * not work when changing directories

cd-commandwildcards

For example I'm in my directory:

/home/myname

and then I want to CD into a different directory.

/home/pulsar/... 

Since I need to go pretty deep into the other directory, how can I go about this without having to type the whole line? I tried

cd */thedirectoryiwanttogointo

but that doesn't work. I have to type the whole line.

Best Answer

Probably your wildcard does not work because:

  • there were no matches for the wildcard from the location you gave, or
  • there was more than one match.

The usual approach (in a shell) to moving frequently among subdirectories is to use the CDPATH feature, as well as pushd and popd.

The CDPATH feature (perhaps first seen in tcsh) is a colon-separated list of directories. If the parent of your thedirectoryiwanttogointo name is reasonably unique, then you could add the parent to the list.

For further reading (your shell's manual page should be first):

pushd and popd are newer than CDPATH, but still dating from the mid-1990s. They allow you to save your current directory ("pushing" onto a stack) and restore it ("popping" from a stack) during their respective cd commands. For further reading:

Other people use shell aliases or symbolic links. Those are most useful when going to well-known locations.