Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. Bash Dictionary
  3. cd / pwd

cd / pwd

cd changes the current directory, and pwd prints the path of the current working directory. Both are essential terminal commands you will use every day.

Syntax

cd [directory]   # Change to the specified directory
pwd              # Print the full path of the current directory

Command List

Command / NotationDescription
cd directoryChanges to the specified directory.
cdWith no arguments, changes to the home directory ($HOME).
cd ~Changes to the home directory. Equivalent to cd with no arguments.
cd -Returns to the previous directory. Useful for toggling between two directories.
cd ..Moves up one level to the parent directory.
cd ../..Moves up two directory levels.
pwdPrints the absolute path of the current working directory to standard output.
pwd -LPrints the logical path without resolving symbolic links (default behavior).
pwd -PPrints the physical path with all symbolic links resolved.

Sample Code

The following examples use this directory structure.

📁 /home/user/ 📁 Documents/ 📁 Projects/ 📁 app/ 📁 Downloads/

Change to the home directory and check the current location.

cd
pwd
/home/user

Change to /var/log using an absolute path.

cd /var/log
pwd
/var/log

Move up one directory level.

cd ..
pwd
/var

Use $ cd - to return to the previous directory. This is handy when you need to switch back and forth between two directories.

cd -
/var/log
cd -
/var

Navigate using a relative path from the home directory.

cd ~/Documents/Projects
pwd
/home/user/Documents/Projects

Move up two directory levels.

cd ../..
pwd
/home/user

Notes

$ cd - toggles between the current directory and the previous one. It is extremely convenient when you need to switch back and forth between two directories during a work session. The previous directory is stored in the environment variable $OLDPWD.

$ pwd is a shell built-in, but an external command (/bin/pwd) also exists. Their behavior can differ under symbolic links, so in scripts it is safer to use $ pwd -P to obtain the physical path.

To list the contents of a directory, use ls.

If you find any errors or copyright issues, please .