Shell productivity: aliases, scripts and dotfiles
Pros don't type faster; they type less. Aliases, history tricks, scripts and a well-tuned shell configuration turn repetitive work into a single word.
History: never retype a command
| Shortcut | Does |
|---|---|
| ↑ / ↓ | Step through previous commands |
| Ctrl + R | Search history as you type (press again for older matches) |
!! |
Repeat the last command: sudo !! reruns it with sudo |
!42 |
Run command number 42 from history |
!$ |
The last argument of the previous command: mkdir new && cd !$ |
Aliases: your own shortcuts
Popular aliases developers add:
alias ll='ls -lah'
alias gs='git status'
alias gc='git commit -m'
alias gp='git push'
alias dc='docker compose'
alias serve='python3 -m http.server 8000'
alias ports='lsof -i -P | grep LISTEN'Aliases vanish when the terminal closes, unless you put them in a dotfile.
Dotfiles: your shell configuration
Files starting with . in your home folder configure your tools. They're called dotfiles.
| Dotfile | Configures |
|---|---|
~/.bashrc / ~/.zshrc |
Your shell: aliases, PATH, prompt, functions |
~/.gitconfig |
Git user, aliases, default branch |
~/.ssh/config |
SSH shortcuts for servers |
~/.vimrc, ~/.config/ |
Editors and other tools |
Many developers keep their dotfiles in a Git repository so they can set up a new laptop in minutes. Search GitHub for "dotfiles" for inspiration.
Shell scripts: save commands as programs
A script is a text file of commands. Run it, and it executes them in order:
Anatomy of a script:
#!/bin/bash ← "shebang": which program runs this file
# comments start with #
echo "Hello, $1!" ← $1 = first argument, $2 = second…
echo "$# args: $@" ← $# = number of arguments, $@ = all of themWrite your own
Create a backup script that copies a folder into a dated backup folder:
On a real machine, write scripts in an editor (
nano backup.sh, or VS Code). Real bash scripts can also useif,forloops, functions and more: see the Bash Scripting track.
Script safety settings
Start serious scripts with this line, so a failing step stops the script instead of carrying on with broken state:
#!/usr/bin/env bash
set -euo pipefail # exit on error, on undefined variables, and on failures inside pipesTools that supercharge your terminal
| Tool | Why |
|---|---|
| Oh My Zsh / Starship | A beautiful prompt showing your git branch, status and language versions |
| fzf | Fuzzy search for files, history (Ctrl + R) and git branches |
zoxide (z) |
Jump to frequently used folders: z web → ~/projects/website |
ripgrep (rg) |
A blazing-fast grep that respects .gitignore |
| bat | cat with syntax highlighting |
| eza | A modern ls with colours and git status |
| tmux | Split panes, and sessions that survive disconnects on servers |
| tldr | Short, practical examples for commands: tldr tar |
🎓 Terminal track complete!
You can navigate, manage files, search and transform text with pipelines, configure your environment, manage permissions and processes, and automate with aliases and scripts. That's the foundation for Git, Docker, Linux servers and Bash scripting.
Practice
- Create aliases
docs(cd ~/Documents) andlogs(tail -n 5 ~/data/app.log) and test them. - Write a script
report.shthat prints the number of ERROR lines and WARN lines in~/data/app.log. Make it executable and run it. - Add an alias to
~/.bashrcwithecho "alias c='clear'" >> ~/.bashrc, thensourceit and test it.
1.In a script, what is $1?
2.How do you make an alias permanent?