cd in Mac OS X

By: Strauss K  

Change Directory - change the current working Folder.

      cd [-L|-P] [dir]

   -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 name. If not, changes to HOME.

$ cd - will go back to the last folder you looked at. (Previous directory - equivalent to $OLDPWD)


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


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

Move up to the parent directory (/Users/kate/)
cd ..

To move up two levels:
$ cd ../..

Move to the top of the boot volume
$ cd /

Move to your home directory
$ cd ~

Move to a folder when the folder name includes spaces, parentheses or any other punctuation:
$ cd 'AppleWorks User Data'

Archived Comments

1. Brettkip
View Tutorial          By: Brettkip at 2017-06-01 00:53:13

Most Viewed Articles (in macos )

Latest Articles (in macos)

Comment on this tutorial