Terminal Toolbox
A quick reference for the core Linux commands used throughout this course. Come back here whenever you need a reminder — this page is a companion to the exercises, not a replacement for working through them.
Orientation & navigation
Finding out where you are and moving around the filesystem.
pwdPrints the absolute path of your current working directory. Your first move whenever you're unsure where you are.
lsLists the contents of the current directory (or a directory you specify).
ls -lhLists contents in "long" format — permissions, owner, size, and modification date — with file sizes shown in human-readable units (K, M, G) rather than raw bytes.
cdChanges your current working directory. cd .. moves up one level; cd with no argument returns you to your home directory; cd - returns you to the previous directory you were in.
Files & directories
Creating, copying, moving, and removing things.
mkdirCreates a new, empty directory. mkdir -p a/b/c creates nested directories in one go, including any missing parent directories.
cpCopies a file (or, with -r, a directory and its contents) to a new location, leaving the original in place.
mvMoves or renames a file or directory. There is no separate "rename" command — moving a file to a new name in the same directory is how renaming works.
rmDeletes a file permanently — there is no undo and no recycle bin. Use rm -r to remove a directory and its contents. Always double-check the path before pressing enter.
Inspecting files
Looking inside files without necessarily opening the whole thing.
headPrints the first lines of a file (10 by default). Use head -n 20 file to control how many lines are shown. Safe to use on huge files since it only reads the start.
lessOpens a file for interactive, scrollable viewing without loading the whole thing into memory at once. Arrow keys / space bar to scroll, /pattern to search, q to quit.
catPrints an entire file's contents to the screen. Useful for small files; avoid on very large files since it will flood your terminal.
fileInspects a file's actual content to report its real type (e.g. "gzip compressed data", "ASCII text"), regardless of what its extension claims.
duReports disk usage. du -sh . summarises the total size of the current directory in human-readable units — far more useful day-to-day than the default verbose, per-file output.
Compression
Most genomic data is distributed compressed.
gzip / gunzip
gzip file compresses file into file.gz (and removes the original by default).
gunzip file.gz reverses this. Add -k to either command to keep the original file
as well as the new one.