Linux Command Line Basics
Navigating the Filesystem
Moving between directories is the skill you will use more than any other on the command line. The command is cd — change directory.
The basics
cd /etc # go to /etc
cd ~ # go to your home directory
cd .. # go up one level
cd - # go back to the previous directory
Relative vs absolute paths
- An absolute path starts with
/and works from anywhere:cd /var/log - A relative path starts from where you are:
cd Documentsmoves into theDocumentsfolder inside your current directory
Shortcuts that save your fingers
| Shortcut | Meaning |
|---|---|
~ |
Your home directory |
. |
The current directory |
.. |
The parent directory |
- |
The last directory you were in |
| Tab | Auto-completes file and folder names |
Press Tab constantly. Type cd /et and press Tab — the shell completes it to cd /etc. When there are multiple matches, press Tab twice to see them all.
Finding your way around
A quick tour of common directories:
| Path | Purpose |
|---|---|
/home |
Where normal users keep their files |
/etc |
System configuration files |
/var/log |
Log files (good for troubleshooting) |
/tmp |
Temporary files, cleared on reboot |
/usr/bin |
Most installed programs |
Try it
cd /etcthenpwd— where are you?ls— can you spothostnameorhosts?cd ~thencd /var/logthencd -— watch the prompt tell you where you are
Advertisement