Introduction
Hello! In this article, we’ll learn about the cd command.
cd stands for “Change Directory”, and it’s a basic command used to change your current working directory. It’s one of the most frequently used commands when working with Linux.
What is the cd Command?
The cd command is a shell built-in command used to move (change) your working directory. By being able to move freely within the file system, you can access files and directories in various locations.
Basic Syntax
|
|
Main Usage Patterns
Moving with Absolute Path
Specify the full path starting from the root directory (/).
|
|
Moving with Relative Path
Specify a location relative to your current directory.
|
|
Useful Special Symbols
| Symbol | Meaning |
|---|---|
~ |
Home directory |
. |
Current directory |
.. |
Parent directory (one level up) |
- |
Previous directory |
Usage Examples
Example 1: Go to Home Directory
|
|
Result:
|
|
Example 2: Go to Parent Directory
|
|
Result:
|
|
Example 3: Return to Previous Directory
|
|
Result:
|
|
Example 4: Go Up Multiple Levels
|
|
Result:
|
|
Example 5: Move with Absolute Path
|
|
Result:
|
|
Tips & Notes
- cd without arguments: Running
cdwithout arguments takes you to your home directory - Paths with spaces: If a path contains spaces, enclose it in quotes (
") or escape with backslash (\)1 2cd "My Documents" cd My\ Documents - Tab completion: When typing paths, press
Tabfor auto-completion - Check current location: Use the
pwdcommand to see your current directory1pwd - Non-existent directory: Trying to move to a non-existent directory will give an error
1 2cd nonexistent-directory # bash: cd: nonexistent-directory: No such file or directory
Practical Usage
Relative Path from Home Directory
You can use ~ to specify a relative path from your home directory.
|
|
CDPATH Environment Variable
If you frequently access certain directories, setting the CDPATH environment variable can be convenient.
|
|
Summary
In this article, we learned about the cd command.
Key Points:
cdis a basic command for moving between directories- Can use both absolute and relative paths
- Special symbols like
~,.,..,-make navigation efficient - Tab completion makes typing easier
The cd command is absolutely fundamental to Linux operations. Master it well for a comfortable command-line experience!
Keep learning Linux commands!