cd ‐ #navigation - five4nets/Linux-Knowledgebase GitHub Wiki
Sure! Here's a complete Markdown tutorial for using the cd
command in Linux:
cd
Command Tutorial
📁 Linux The cd
(change directory) command is one of the most essential tools in Linux. It allows users to navigate the filesystem from the command line.
🧰 Basic Syntax
cd [OPTION] [DIRECTORY]
- DIRECTORY: The path to the directory you want to move into.
- OPTION: Optional flags like
-L
or-P
for symbolic link behavior.
🔄 Common Use Cases
1. Go to the Home Directory
cd
cd ~
2. Move to a Specific Directory
cd /var/log
3. Use a Relative Path
cd Documents/Projects
4. Go Up One Level
cd ..
5. Go Up Multiple Levels
cd ../../
6. Return to the Previous Directory
cd -
7. Handle Spaces in Directory Names
cd "My Documents"
cd My\ Documents
8. Use Absolute vs. Relative Paths
- Absolute:
cd /home/user/Documents
- Relative:
cd Documents
⚙️ Options
Option | Description |
---|---|
-L |
Follow symbolic links (default) |
-P |
Use the physical directory structure (ignore symlinks) |
🧠 Tips
- Use
pwd
to print your current directory:pwd
- Use tab completion to auto-complete directory names.
- Use
alias
to create shortcuts:alias docs="cd ~/Documents"
📚 References
- GeeksforGeeks: cd Command in Linux
- Linux Handbook: cd Command Examples
- Linuxize: cd Command in Linux
- Baeldung: Guide to cd Command
Happy navigating! 🧭
Let me know if you'd like a version that includes `pushd` and `popd` for advanced directory stack navigation!