Shell basics — navigation & files
The core commands you use every day: moving around the filesystem, listing, reading, copying, and inspecting files.
Path resolution: absolute paths start with / (/etc/passwd); relative paths resolve from $PWD. Tilde ~ expands to $HOME, ~user to another user's home, ~- to $OLDPWD. The shell expands paths before handing them to commands — so ls ~ passes /home/you to ls, not the literal tilde.
ls flags worth memorizing: -l (long form: permissions, size, mtime), -a (include dotfiles), -h (human-readable sizes: 4.0K, 2.3M), -t (sort by mtime, newest first), -S (by size), -1 (one per line — useful in pipelines). Combined: ls -lha is the default for 'show me everything'.
File permissions (ls -l leftmost column: -rwxr-xr--): first char is type (- file, d directory, l symlink), then three triplets for owner/group/others — read/write/execute. chmod 755 sets rwxr-xr-x; chmod +x script.sh adds execute for all. Octal (digits) vs symbolic (u+x, g-w) — either works.
Safe deletion patterns: rm -rf is irreversible. Defensive moves: use rm -i for interactive confirm, set set -u and set -e in scripts (unset vars abort instead of expanding to empty and nuking $PREFIX/), prefer find -delete with explicit predicates, or move to a trash directory instead of deleting. Never use rm -rf $VAR/ without guarding against empty $VAR.
Inspection toolkit: stat file (full metadata: inode, size, timestamps), file name (detects type by magic bytes — not extension), du -sh dir (recursive size), df -h (disk usage by mount), wc -l file (line count), which cmd vs command -v cmd (location of executable in PATH; the latter is portable across shells).
Globs vs regex: ls *.log expands via the shell's pathname expansion (globbing — a filesystem match, not a regex). * matches any characters except /, ? matches one char, [abc] a set. Globbing happens BEFORE the command runs; by the time ls executes, the shell has already replaced *.log with the matching filenames.
Grounded on https://tldp.org/LDP/Bash-Beginners-Guide/html/
Next up
Pipes & redirections
Connect the output of one command to the input of another (`|`), or send it to a file (`>`, `>>`). The core composition tool of Unix.