0
0
Linux CLIscripting~3 mins

cd (change directory) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you work in a command line, you often need to move between folders to find files or run programs. The cd command helps you change your current folder to another one so you can work there.
When you want to open a folder to see or work with its files.
When you need to run a program or script located in a different folder.
When you want to organize your work by moving into project-specific folders.
When you want to go back to your home folder quickly.
When you want to move up one level in the folder structure.
Commands
This command changes your current folder to /usr/local/bin so you can work with files there.
Terminal
cd /usr/local/bin
Expected OutputExpected
No output (command runs silently)
This command shows the full path of your current folder to confirm you changed directories.
Terminal
pwd
Expected OutputExpected
/usr/local/bin
This command moves you up one folder level from your current location.
Terminal
cd ..
Expected OutputExpected
No output (command runs silently)
Check your current folder again to see that you moved up one level.
Terminal
pwd
Expected OutputExpected
/usr/local
This command takes you back to your home folder quickly.
Terminal
cd ~
Expected OutputExpected
No output (command runs silently)
Confirm you are now in your home folder.
Terminal
pwd
Expected OutputExpected
/home/username
Key Concept

If you remember nothing else, remember: cd changes your current folder so you can work in different places on your computer.

Common Mistakes
Typing cd with a folder name that does not exist.
The command fails because the folder is not found, so you stay in the same place.
Check the folder name carefully or use ls to list folders before changing directory.
Using cd without any arguments expecting it to go to root folder.
cd without arguments goes to your home folder, not root.
Use cd / to go to the root folder explicitly.
Forgetting that folder names are case sensitive.
cd fails if the folder name case does not match exactly.
Type folder names exactly as they appear, respecting uppercase and lowercase letters.
Summary
Use cd followed by a folder path to move to that folder.
Use cd .. to move up one folder level.
Use cd ~ to quickly return to your home folder.