01
Navigation & Paths
- Where am I
- List a deploy directory
- Explain absolute vs relative path
- Recover from wrong directory mid-troubleshoot
Must-know cold
pwd·cd /path·cd/cd ~·cd -·cd ..ls -la·ls -lh·ls -lt- Absolute path starts with
/~= home.= here..= parent
Path concepts
| Token | Argument | Meaning | Example |
|---|---|---|---|
/ | — | Root of filesystem; absolute paths start here | /var/log |
~ | — | Current user’s home directory | cd ~ → /home/you |
. | — | Current directory | ls . |
.. | — | Parent directory | cd .. |
- | — | Previous directory (for cd only) | cd - |
Commands
pwd
Definition: Print the absolute path of the current working directory.
| Option | Argument | Meaning | Example |
|---|---|---|---|
| (none) | — | Print working (current) directory absolute path | pwd |
-P | — | Resolve symlinks; show physical path | pwd -P |
-L | — | Show logical path (default; may keep symlink path) | pwd -L |
Flag combos
| Combo | Meaning | Example |
|---|---|---|
pwd -P | Real path after symlink dirs | cd /lib; pwd -P |
cd
Definition: Change the current working directory (or jump home / previous).
| Option | Argument | Meaning | Example |
|---|---|---|---|
| (none) | — | Go to $HOME | cd |
| (none) | DIR | Change to directory | cd /var/log |
| (none) | - | Go to previous directory | cd - |
| (none) | ~ | Go home (same as bare cd) | cd ~ |
| (none) | ~user | Go to that user’s home | cd ~jenkins |
-P | DIR | Resolve symlinks when changing | cd -P /link/to/dir |
-L | DIR | Follow logical path (default) | cd -L somedir |
Flag combos
| Combo | Meaning | Example |
|---|---|---|
cd / && pwd | Jump root and confirm | cd /var && pwd |
cd ../.. | Up two levels | cd ../.. |
ls
Definition: List directory entries; with flags, show metadata, sorting, and hidden files.
| Option | Argument | Meaning | Example |
|---|---|---|---|
| (none) | — | List names in current dir | ls |
| (none) | PATH | List that file/dir | ls /etc |
-l | — | Long format (mode, owner, size, mtime, name) | ls -l |
-a | — | Include hidden (names starting with .) | ls -a |
-A | — | Almost all; hidden but not . and .. | ls -A |
-h | — | Human-readable sizes (with -l) | ls -lh |
-t | — | Sort by modification time (newest first) | ls -lt |
-S | — | Sort by size (largest first) | ls -lS |
-r | — | Reverse sort order | ls -ltr |
-R | — | Recursive list | ls -R |
-d | — | List directory itself, not contents | ls -ld /tmp |
-1 | — | One name per line | ls -1 |
-i | — | Show inode number | ls -li |
-F | — | Classify (/ dir, * exec, @ link) | ls -F |
Flag combos
| Combo | Meaning | Example |
|---|---|---|
ls -la | Long + all hidden | ls -la ~ |
ls -lah | Long + all + human sizes | ls -lah /var/log |
ls -ltr | Long, oldest→newest (log triage) | ls -ltr /var/log |
ls -lS | Long, largest files first | ls -lS |
ls -ld dir | Metadata of dir, not listing inside | ls -ld /etc/nginx |
tree
Definition: Display the directory hierarchy as an indented tree. Optional package — install if missing.
| Option | Argument | Meaning | Example |
|---|---|---|---|
| (none) | — | Print directory tree | tree |
| (none) | DIR | Tree starting at DIR | tree /etc/nginx |
-L | N | Max depth N | tree -L 2 |
-a | — | Include hidden | tree -a |
-d | — | Directories only | tree -d |
-h | — | Human sizes | tree -h |
Flag combos
| Combo | Meaning | Example |
|---|---|---|
tree -L 2 -d | Shallow dir map | tree -L 2 -d /opt |
Common recipes
| Goal | Command |
|---|---|
| Where am I? | pwd |
| Go home | cd or cd ~ |
| Toggle last two dirs | cd - |
| List everything useful | ls -lah |
| Newest files in log dir | ls -ltr /var/log | tail |
| Dir permissions only | ls -ld /path/to/dir |
| Confirm path after cd | cd /var/lib/jenkins && pwd |
Pitfalls
- Relative paths depend on current directory — always
pwdwhen lost. lswithout-ahides.env,.git,.ssh.ls -lsize is not always “disk used” for dirs (usedu).cdto a file fails;cdto a symlink may show the logical path (pwd -Pto verify).
For more details, try man <command> in your terminal.