undocumented? Bourne shell / bash feature: cd –

A while ago, I learned something new about the ‘cd’ command:

  cd -

This changes directory back to the previous directory you were in.  You can do it again to move back and forth.  Quite useful!  a bit like a simpler pushd/popd/dirs.

It’s not documented in bash online help, manpage or info doc as far as I can see.  I guess it’s an old feature inherited from the Bourne shell; other Bourne-compatible shells have this feature too, even C shell has it.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to undocumented? Bourne shell / bash feature: cd –

  1. Grumpy says:

    On debian “man cd” describes the behaviour in detail.

  2. Chris Samuel says:

    “cd” is a bash builtin and this behaviour is documented in the bash manpage in both Ubuntu 10.10 and in Debian Lenny:

           cd [-L|-P] [dir]
                  Change  the  current directory to dir.  The variable HOME is the
                  default dir.  The variable CDPATH defines the  search  path  for
                  the  directory  containing  dir.  Alternative directory names in
                  CDPATH are separated by a colon (:).  A null directory  name  in
                  CDPATH  is  the  same as the current directory, i.e., ``.''.  If
                  dir begins with a slash (/), then CDPATH is  not  used.  The  -P
                  option  says  to use the physical directory structure instead of
                  following symbolic links (see also the  -P  option  to  the  set
                  builtin command); the -L option forces symbolic links to be fol‐
                  lowed.  An argument of - is equivalent to $OLDPWD.   If  a  non-
                  empty  directory  name from CDPATH is used, or if - is the first
                  argument, and the directory change is successful,  the  absolute
                  pathname of the new working directory is written to the standard
                  output.  The return value is true if the directory was  success‐
                  fully changed; false otherwise.

    Hope that helps!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s