Linux Terminal Essentials Every Developer Needs
The handful of terminal commands and shortcuts I use every day for navigating, searching, piping output, and managing jobs on Linux.
On this page
You can do a lot of development work without ever leaving the terminal, but only if a small core of commands is second nature. This is the set I reach for daily. None of it is exotic, and all of it works in a stock bash installation, so you can rely on it on a fresh server, in a container, or on a colleague’s laptop.
Navigating the filesystem
Start with knowing where you are and what is around you.
pwd # print the current directoryls -la # long listing, including hidden filescd - # jump back to the previous directorycd # with no argument, go homecd - is the one people tend to miss. It toggles between two directories, which is handy when you are bouncing between a source tree and a log folder.
When you need more than two places, use a directory stack:
pushd ~/projects/api # go there, remember where you werepushd /var/log # stack another onedirs -v # show the stack with indexespopd # return to the previous entryFinding things
find locates files by name, type, size, or age. grep searches inside them.
find . -name "*.ts" -not -path "./node_modules/*"find . -type f -mtime -1 # files changed in the last daygrep -rn "TODO" src/ # recursive, with line numbersgrep -rni --include="*.md" "systemd" .If you search code often, install ripgrep (rg). It respects .gitignore, skips binary files, and is much faster on large repositories. The equivalent of the first grep above is simply rg -n TODO src/.
Pipes and redirection
Every program has standard output (1) and standard error (2). Pipes and redirects let you connect them.
ps aux | grep node | wc -l # chain commands with |ls -la > listing.txt # overwrite a fileecho "done" >> build.log # append to a filemake > build.log 2>&1 # send both streams to one filemake 2>&1 | tee build.log # watch the output and save itThe order in 2>&1 matters: it means “send stderr to wherever stdout points right now”, so it must come after the > redirect. tee is the right tool when you want to see output live and keep a copy.
Viewing files
Avoid dumping large files with cat. Use a pager or look at the edges.
less +F app.log # follow mode; Ctrl-C to stop following, q to quithead -n 20 data.csv # first 20 linestail -n 50 app.log # last 50 linestail -f app.log # stream new lines as they arriveInside less, /pattern searches forward, n jumps to the next match, and G goes to the end.
Job control
A long-running command does not have to block your shell.
Ctrl-Cstops the foreground process.Ctrl-Zsuspends it and returns your prompt.bgresumes the suspended job in the background.fgbrings it back to the foreground.jobslists what the current shell is managing.
npm run build # takes a while... press Ctrl-Zbg # let it continue in the backgroundjobs # [1]+ Running npm run build &fg %1 # bring job 1 backFor work that must survive closing the terminal, look at tmux or a proper service; I cover the latter in systemd basics.
Searching your history
Press Ctrl-R and start typing. Bash searches backwards through history for a matching command; press Ctrl-R again to cycle to older matches, Enter to run, or the right arrow to edit first. Combined with history | grep docker, you rarely need to retype anything long.
Habits worth building
- Tab-complete everything. It prevents typos and teaches you what exists.
- Use
manand--helpbefore searching the web;tldrpages are a nice shortcut for examples. - Quote paths and patterns that contain spaces or wildcards.
- Preview destructive commands first, for example run the
findcommand on its own before adding-delete. - Turn repeated command lines into aliases once they annoy you. I wrote about that in shell aliases and functions.
What to do next
Pick two items from this list that you do not use yet, such as cd - and Ctrl-R, and force yourself to use them for a week. Once they are automatic, add the next pair. Small, deliberate repetition beats reading another cheat sheet.