cd
The builtin that changes the shell's current working directory.
In more detail
cd .. moves up one level, cd on its own goes to your home directory, and cd - goes back to the previous directory. It fails, and returns a non-zero status, if the directory does not exist or you lack permission, so scripts write cd dir || exit to avoid carrying on in the wrong place.
Examples
cd ~/projectcd -cd notes || exit 1cd doracd ../cookbookcd ~/python
python3 hello.pyRelated terms
- current working directory — The directory a shell or process is standing in, where any relative path or bare file name is looked up.
- home directory — Your personal directory, such as /home/ada on Linux or /Users/ada on macOS, where your files and settings live.
- SC2164 — The ShellCheck warning for a cd whose failure is not handled, so the script would carry on in the wrong directory.
- builtin — A command implemented inside the shell itself rather than as a separate program on disk, such as cd, read or export.
- Bash — The GNU shell: a program that reads commands, typed or from a script, and runs them.
- pwd — The command that prints the full path of the current working directory.
- ls — The command that lists the files and directories inside a directory.
- dir command — The Windows Command Prompt command that lists the files and folders in a directory.
Taught in
- What A Shell Is, And What Bash Is — Bash Scripting & Command Line Automation
- Moving Around: pwd, ls, cd And Paths — Bash Scripting & Command Line Automation
- Help, History, Completion And Aliases — Bash Scripting & Command Line Automation
- What Bash Does To A Line Before It Runs It — Bash Scripting & Command Line Automation
- The Unquoted Variable: Splitting And Globbing — Bash Scripting & Command Line Automation
- Command Substitution And Subshells — Bash Scripting & Command Line Automation
- ShellCheck — Bash Scripting & Command Line Automation
- What DevOps Actually Is — DevOps & Site Reliability Engineering
- Throughput: Change Lead Time And Deployment Frequency — DevOps & Site Reliability Engineering
- Instability: Change Fail Rate And Deployment Rework Rate — DevOps & Site Reliability Engineering
- Restoration: Failed Deployment Recovery Time — DevOps & Site Reliability Engineering
- The Pitfalls Of Measurement — DevOps & Site Reliability Engineering
- Codebase And Dependencies — DevOps & Site Reliability Engineering
- Continuous Integration — DevOps & Site Reliability Engineering
- Testing Strategies And The Test Pyramid — DevOps & Site Reliability Engineering
- Building And Versioning The Artifact — DevOps & Site Reliability Engineering
- A Repository Is A Folder With A Memory — Advanced Git Internals & Distributed Workflows
- First Run, And Fixing A Broken Install — Hands-on Python: Complete Video Course & Book
- Windows And Mac Specifics — Hands-on Python: Complete Video Course & Book
- Virtual Environments — Hands-on Python: Complete Video Course & Book
- Three Audit Findings And A Phone: Password Policy, Lockouts And MFA — CompTIA Linux+ (XK0-006) Exam Prep
- The Cleanup That Emptied The Wrong Directory: Shell Scripts Under Exam Conditions — CompTIA Linux+ (XK0-006) Exam Prep
- A New Depot By Friday: OpenTofu, Cloud-init, Pipelines And Kubernetes — CompTIA Linux+ (XK0-006) Exam Prep
- Variables, The PATH And The History — LPIC-1 Linux Administrator (101-500 and 102-500) Exam Prep
- Git And VS Code: Clone, Commit, Push, And The Dev Container — RHCE in Ansible (EX294): Automate Red Hat Systems