cd

Change Directory - change the current working Folder.

Syntax 
      cd [-L|-P] [dir]

Key
   -P   Use the physical directory structure instead of following symbolic links
        (see also the -P option to the set builtin command)

   -L   Force symbolic links to be followed

If a dir is given, changes the shell’s working directory to dir. If not, changes to HOME (shell variable).

$ cd - will go back to the last folder you looked at. This does not stack, so issuing CD - repeatedly will just toggle between two directories, to go back further use pushd/popd. Previous directory - equivalent to $OLDPWD

./ or just . is shorthand for the current directory.

CDPATH

The shell variable CDPATH provides a useful feature, this variable is similar to PATH but it sets up a list of paths where cd will search for subdirectories. CDPATH can be set on the command line for use in the current session, or in .bash_profile for permanent use, the list of paths must be colon separated (:)

$ CDPATH=".:~:~/Library"

If dir begins with a slash (/), then CDPATH is not used.

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 successfully changed; false otherwise.

This is a BASH shell builtin, to display your local syntax from the bash prompt type: help cd

Examples

Move to a subfolder named "Documents":

$ cd Documents

Move to the fonts folder:

$ cd /library/fonts
$ pwd
cd /library/fonts

Change to another folder:

$ cd ~/music
$ pwd
/Users/kate/music

Move up to the parent directory (/Users/kate/):

cd ..

Move up two levels:

$ cd ../..

Move to the top of the boot volume:

$ cd /

Move to your home directory:

$ cd ~
or just:
$ cd

Move to a folder when the folder name includes spaces, parentheses or any other punctuation:

$ cd 'AppleWorks User Data'

“In times of change, learners inherit the earth, while the learned find themselves equipped to deal with a world that no longer exists” ~ Eric Hoffer

Related

popd - Restore the previous value of the current directory.
pushd - Save and then change the current directory.
pwd - Print Working Directory.


 
Copyright © 1999-2024 SS64.com
Some rights reserved