Skip to main content

How to Move into a Folder in the Terminal with cd

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A terminal always works inside one folder, and most commands act on that folder. cd moves you to another one, and pwd tells you where you are. Four forms of cd cover almost every move you'll make.

Syntax​

The same commands work in zsh, bash and PowerShell:

Syntax
cd <folder>
cd ..
cd ~
cd -
pwd
PartWhat it does
cdShort for "change directory". Moves you to another folder.
<folder>The folder to move into: a name inside the folder you're in, or a full path such as /Users/you/notes.
..The folder that contains the one you're in, one level up.
~Your home folder.
-The folder you were in before the last move.
pwdShort for "print working directory". Prints the folder you're in.

In PowerShell, cd is another name for Set-Location and pwd for Get-Location. cd - has worked there since PowerShell 6.2, which keeps a history of your last 20 locations.

The Example​

The terminal starts in the home folder. The example creates a notes folder, moves into it, moves back up, jumps home from inside it, and then returns to it with cd -.

Step 1: See Where You Are​

Terminal
pwd
Output
/Users/Shared/you

This home folder is /Users/Shared/you. Yours is your own, usually /Users/<your name> on a Mac, /home/<your name> on Linux and C:\Users\<your name> on Windows.

Step 2: Move into a Folder​

Create a folder to move into, then move into it:

Terminal
mkdir notes
cd notes
pwd
Output
/Users/Shared/you/notes

How to Create a Folder in the Terminal with mkdir explains the first command. cd prints nothing when it works: the next pwd shows the move.

Step 3: Move Back Up​

Terminal
cd ..
pwd
Output
/Users/Shared/you

Step 4: Jump Home, Then Back​

cd ~ goes home from anywhere, and cd - returns to the folder you just left:

Terminal
cd notes
cd ~
pwd
cd -
Output
/Users/Shared/you
~/notes

cd - prints the folder it moved to, with ~ standing for the home folder.

A zsh terminal where pwd prints the home folder, cd notes moves into notes, cd .. moves back up, cd ~ goes home and cd - returns to ~/notes.

Common Mistakes​

MistakeWhat happensDo this instead
A folder name with a space and no quotes: cd my notesThe shell sees two names and doesn't go thereQuote it: cd "my notes"
Assuming a new terminal opens where the last one wasA new terminal window usually starts in your home foldercd into the folder again
Running a project's commands from the wrong folderThey can't find the project's filesCheck with pwd, then cd into the project

Troubleshooting​

SymptomLikely causeFix
cd: no such file or directory: notes in zsh, or cd: notes: No such file or directory in bashThere's no notes in the folder you're inCheck where you are with pwd, or use the full path
cd - goes somewhere unexpectedIt returns to the last folder you were in, not one level upUse cd .. to go up

FAQ​

Is there a shortcut for the home folder?​

Yes: cd on its own goes home in zsh and bash, the same as cd ~.

Do the same commands work on Windows?​

In PowerShell, yes: cd, cd .., cd ~, cd - and pwd all work.

Conclusion​

cd <folder> moves into a folder, cd .. moves up one level, cd ~ goes home and cd - returns to the last folder. pwd shows where you are, and it's worth running whenever a command can't find a file.

Additional Resources​