Kiet Nguyen logo
NotesNotesResumeResume
© 2026 Kiet Nguyen
← All categories

01

Navigation & Paths

  • Where am I
  • List a deploy directory
  • Explain absolute vs relative path
  • Recover from wrong directory mid-troubleshoot
pwdcdlstree

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

TokenArgumentMeaningExample
/—Root of filesystem; absolute paths start here/var/log
~—Current user’s home directorycd ~ → /home/you
.—Current directoryls .
..—Parent directorycd ..
-—Previous directory (for cd only)cd -

Commands

pwd

Definition: Print the absolute path of the current working directory.

OptionArgumentMeaningExample
(none)—Print working (current) directory absolute pathpwd
-P—Resolve symlinks; show physical pathpwd -P
-L—Show logical path (default; may keep symlink path)pwd -L

Flag combos

ComboMeaningExample
pwd -PReal path after symlink dirscd /lib; pwd -P

cd

Definition: Change the current working directory (or jump home / previous).

OptionArgumentMeaningExample
(none)—Go to $HOMEcd
(none)DIRChange to directorycd /var/log
(none)-Go to previous directorycd -
(none)~Go home (same as bare cd)cd ~
(none)~userGo to that user’s homecd ~jenkins
-PDIRResolve symlinks when changingcd -P /link/to/dir
-LDIRFollow logical path (default)cd -L somedir

Flag combos

ComboMeaningExample
cd / && pwdJump root and confirmcd /var && pwd
cd ../..Up two levelscd ../..

ls

Definition: List directory entries; with flags, show metadata, sorting, and hidden files.

OptionArgumentMeaningExample
(none)—List names in current dirls
(none)PATHList that file/dirls /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 orderls -ltr
-R—Recursive listls -R
-d—List directory itself, not contentsls -ld /tmp
-1—One name per linels -1
-i—Show inode numberls -li
-F—Classify (/ dir, * exec, @ link)ls -F

Flag combos

ComboMeaningExample
ls -laLong + all hiddenls -la ~
ls -lahLong + all + human sizesls -lah /var/log
ls -ltrLong, oldest→newest (log triage)ls -ltr /var/log
ls -lSLong, largest files firstls -lS
ls -ld dirMetadata of dir, not listing insidels -ld /etc/nginx

tree

Definition: Display the directory hierarchy as an indented tree. Optional package — install if missing.

OptionArgumentMeaningExample
(none)—Print directory treetree
(none)DIRTree starting at DIRtree /etc/nginx
-LNMax depth Ntree -L 2
-a—Include hiddentree -a
-d—Directories onlytree -d
-h—Human sizestree -h

Flag combos

ComboMeaningExample
tree -L 2 -dShallow dir maptree -L 2 -d /opt

Common recipes

GoalCommand
Where am I?pwd
Go homecd or cd ~
Toggle last two dirscd -
List everything usefulls -lah
Newest files in log dirls -ltr /var/log | tail
Dir permissions onlyls -ld /path/to/dir
Confirm path after cdcd /var/lib/jenkins && pwd

Pitfalls

  • Relative paths depend on current directory — always pwd when lost.
  • ls without -a hides .env, .git, .ssh.
  • ls -l size is not always “disk used” for dirs (use du).
  • cd to a file fails; cd to a symlink may show the logical path (pwd -P to verify).

For more details, try man <command> in your terminal.

Previous00 Introduction to GNU BashNext02 File & Directory Operations