核心 · Key Idea
In one line: the Linux philosophy is "everything is a file + small composable tools". Master a few dozen commands plus redirection and pipes and you can do 90 % of day-to-day ops.
Directory layout (FHS)#
/etc Global config (nginx.conf, systemd units)
/var Variable data (logs in /var/log, DBs in /var/lib)
/usr Distro programs and libraries
/opt Third-party self-contained apps
/home User home directories
/root Root user's home
/tmp Temp files, wiped on reboot
/proc /sys Kernel virtual filesystems (process info / kernel knobs)
Every file / device / network socket appears as a path — that's "everything is a file".
Analogy#
打个比方 · Analogy
Linux is a box of Lego bricks — each command (grep / sort / awk) is one brick; pipe them together with | to build any shape. Windows leans toward "one giant app solves everything".
Must-know commands by category#
- View / browse
- ls / cat / less / tail / head / file
- Navigate
- cd / pwd / pushd / popd
- File ops
- cp / mv / rm / mkdir / ln
- Search
- find / grep / rg (ripgrep) / locate
- Processes
- ps / top / htop / kill / pgrep
- Permissions
- chmod / chown / chgrp
- Network
- ip / ss / curl / dig
- Archives
- tar / gzip / zstd / unzip
- Text
- sed / awk / cut / sort / uniq / wc
Redirection and pipes#
cmd > file # stdout to file (overwrite)
cmd >> file # append
cmd 2> err.log # redirect stderr
cmd > out 2>&1 # both into out
cmd1 | cmd2 # cmd1's stdout becomes cmd2's stdin
< file cmd # stdin from file| is Linux's most powerful idea:
ps aux | grep nginx | awk '{print $2}' | xargs kill -9How it works#
Each command is a fork + exec'd process; stdin / stdout / stderr are its "three pipes".
Practical notes#
man cmd/tldr cmd— man is canonical; tldr is a quick cheatsheet of common usage.- Use
xargsto convert stdin to arguments:find . -name '*.log' | xargs rm -f. rm -rfcautiously — especially with variables. Echo first:echo rm -rf "$DIR"/*.- Env vars:
export VAR=valfor the current shell; persist in~/.bashrc/~/.zshrc. - Background:
cmd &runs in background;nohup cmd > log 2>&1 &survives logout. In production use systemd. - History search: Ctrl+R reverse-searches your history — far faster than ↑.
Easy confusions#
bash
Default on nearly every distro.
Best script compatibility.
Best script compatibility.
zsh
macOS default; oh-my-zsh is delightful.
Slight script-syntax drift from bash.
Slight script-syntax drift from bash.