Linux Terminal and Shell Scripting
On-ramp to the Linux terminal for Windows-comfortable engineers: navigation, shell config, dotfiles management, tmux, and safe shell scripting.
This path goes from “comfortable on Windows” to “comfortable on the command line.” It covers core commands, shell config, versioned dotfiles, tmux, and turning repeated manual steps into scripts you can trust.
Learning path
Steps
- Learn the eight commands you use most days:
pwd,cd,ls,mkdir,touch,cp,mv,rm,cat. On Windows, WSL or Git Bash is enough to start practicing. - Identify your shell:
echo $SHELLshows whether you use Bash (~/.bashrc) or Zsh (~/.zshrc). Editing the wrong file wastes a lot of time. - Customize your shell config: add aliases (
alias gs='git status'), export variables (PATH,EDITOR), define functions. Reload withsource ~/.bashrcto test changes without restarting the terminal. - Pick one dotfiles tool early, before your config builds up clutter:
- Bare git repo: minimal, no extra tooling.
- GNU Stow: symlink-based, no dependencies:
stow -d ~/dotfiles -t ~ <package>. - chezmoi: supports templating (
{{ .hostname }}) for one repo across Windows/macOS/Linux.
- Learn tmux’s hierarchy. A session holds windows, and each window holds panes. Start a session with
tmux new -s work. The default prefix key isCtrl+b. - Navigate tmux: split panes with
Prefix "(horizontal) orPrefix %(vertical). Switch windows withPrefix 1-9. Detach withPrefix d, then reattach later withtmux attach -t work. Many people change the prefix toCtrl+ain~/.tmux.conf. - Write scripts with safe defaults. Start every script with this header:
Run each script through#!/usr/bin/env bash set -o errexit set -o nounset set -o pipefailshellcheckbefore you rely on it. - Handle arguments and unset variables with care. Quote everything (
"${VAR-}"), support-hand--help, and turn on trace mode only when you need to debug ([[ -n "${TRACE-}" ]] && set -o xtrace).
Tips
- Use
#!/usr/bin/env bashinstead of#!/bin/bash. It works on more systems, where bash may not be at that exact path. - Run
bash script.shbeforechmod +x. This catches syntax errors without marking the file executable. - Use
tmux lsandtmux kill-session -t <name>to manage background sessions. Detached sessions survive SSH disconnects, which matters most for remote work. - chezmoi templates let one dotfiles repo cover Windows, macOS, and Linux without exposing machine-specific paths.
Common pitfalls
- Editing the wrong rc file (
.bashrcwhen you run zsh). Aliases and functions seem broken. Check$SHELLfirst. - Forgetting
set -o pipefail: a script can report success when a command in the middle of a pipeline fails. - Committing secrets in dotfiles: API keys or SSH keys in a public repo cause a breach that is hard to undo. Use chezmoi’s encryption or yadm’s encrypt feature for anything sensitive.
- Stow failing on pre-existing files: it does not overwrite conflicting dotfiles already in
~. Back them up or remove them first. rm -rfwithout checking the path first: runls <path>before deleting. Deletes cannot be undone.- Referencing
${VAR}underset -uwithout a default: use${VAR-default}so an unset variable does not stop the script. - Scripts that grow without functions or
localvariables: they become hard to maintain. Split the logic into functions and use local variables.
Related
Sources
- Shell Script Best Practices - Sharat’s
- Tmux Tutorial: The Complete Developer Workflow Guide (2026) - DEV Community
- Why use chezmoi? - chezmoi
- Linux Command Line Tutorial - freeCodeCamp
- Understanding bashrc and zshrc - Medium
- Dotfile management using GNU stow - Tushar Chauhan
- Exploring Tools For Managing Your Dotfiles - GBergatto
- How to Use set -e -o pipefail in Bash, and Why