Linux CLI Best Practices
A condensed summary of the 25 most important best practices drawn from every page in this section.
Search across all documentation pages
A condensed summary of the 25 most important best practices drawn from every page in this section.
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥
kill <PID> (SIGTERM) first so the process can close files, release locks, and flush buffers; reach for kill -9 only after a graceful stop fails.Restart=on-failure, RestartSec, WorkingDirectory, and Environment=NODE_ENV=production so the app restarts cleanly on crash and survives reboots.tmux (or register it as a service) instead of relying on nohup … &.sudo ufw allow 22/tcp before sudo ufw enable or the next reconnect will be locked out and you will need console access to recover.systemctl status → journalctl -u <svc> --since … → dmesg | tail so you catch both application errors and kernel-level OOM kills.chmod 600 for .env and credential files (owner read/write only), 755 for executables and scripts, and 644 for regular content.rg is substantially faster on large codebases and auto-respects .gitignore, so it skips node_modules/ and .next/ without manual excludes./ or the project root unfiltered - pass a directory and -not -path "*/node_modules/*" (or --exclude-dir=node_modules) so searches finish in seconds instead of minutes.., (, [, or |, pass grep -F/rg -F so the string is matched literally instead of interpreted as regex.sed -i in-place edits require an empty backup argument on macOS (sed -i '' 's/…/…/g' file), which is different from Linux; install gnu-sed if you want portable scripts.grep regex does not support \d, \w, +, or lookaheads, so switch to grep -E/grep -P (or just use rg) when the pattern needs them.xargs splits on whitespace and breaks on spaces in paths, so pair find … -print0 with xargs -0 (or always quote "$file") when filenames are not guaranteed clean.-C 2 (or -A/-B) so you see the surrounding lines instead of re-opening each hit in an editor.set -euo pipefail at the top of every shell script so the script exits on the first error, treats undefined variables as errors, and does not silently swallow failures in the middle of a pipe.~/.bashrc; keep aliases and functions in ~/.zshrc (or source bashrc from it) or they will appear to vanish in new terminals.$(…) for command substitution because it nests cleanly ($(echo $(date))) and reads better; backticks require awkward escaping and mix poorly with quoting.cmd > out.log 2>&1 (stderr follows stdout to the file) - reversing the order sends stderr to the terminal instead.xargs -P 4 -I {} to run up to four in parallel and use -I {} as an explicit placeholder for clarity.npm ci installs the exact versions in package-lock.json, deletes node_modules first, and is faster than npm install, which can quietly update the lockfile and produce non-reproducible builds..nvmrc (e.g., 22) and set "engines": { "node": ">=22" } in package.json so teammates and CI run the same Node version and nvm use auto-switches in the project.NEXT_PUBLIC_ in Next.js; without the prefix they resolve to undefined at runtime, while unprefixed vars stay safely server-only.create-next-app, tsc, or prettier via npx so you always get the project-local version and avoid global-vs-local conflicts that silently change behavior.EADDRINUSE :3000 hits, either run lsof -ti :3000 | xargs kill -9 to reclaim the port or start the app on a different one with PORT=3001 npm run dev.FATAL ERROR: Allocation failed during builds with NODE_OPTIONS="--max-old-space-size=8192" npm run build, but treat repeated OOMs as a signal to audit dependencies or memory leaks rather than raising the limit forever.Reviewed by Chris St. John·Last updated Jul 19, 2026
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥