Linux
Essential Linux Commands for Bioinformatics
A practical cheat sheet of the Linux commands you'll actually use day-to-day when working with sequencing data.
30 August 20262 min read
clishellngs
Most bioinformatics pipelines live on the command line - FASTQ files, BAM files, and VCFs are all just text or binary streams that Linux tools are extremely good at moving, filtering, and inspecting. This is the small set of commands that covers most day-to-day work.
Navigating and inspecting files
# Where am I, what's here
pwd
ls -lh
# Peek at the start/end of a large file without opening it
head -n 20 sample.fastq
tail -n 20 sample.fastq
# Count lines (FASTQ records = line count / 4)
wc -l sample.fastqWorking with compressed data
Sequencing files are almost always gzipped. You rarely need to fully decompress them:
# View without decompressing to disk
zcat sample.fastq.gz | head -n 8
# Count reads in a gzipped FASTQ
zcat sample.fastq.gz | echo $(( $(wc -l) / 4 ))Searching and filtering
# Find all reads containing a specific adapter sequence
grep -c "AGATCGGAAGAGC" sample.fastq
# Extract just the header lines from a FASTQ
grep "^@" sample.fastqPiping tools together
The real power of the shell is chaining small tools. A common pattern - count how many reads in a BAM file are mapped:
samtools view -c -F 4 aligned.bamOr extract a region of interest from a VCF and count variants:
bcftools view -r chr17:41196312-41277500 variants.vcf.gz | grep -vc "^#"Permissions and processes
# Make a script executable
chmod +x run_pipeline.sh
# Watch a long-running job
top
# or, nicer:
htop
# Run something that should survive a disconnected SSH session
nohup ./run_pipeline.sh &A few habits worth building
- Always
zcat | headbefore running a tool on a new file - know what you're feeding it. - Use
wc -las a sanity check after every filtering step; unexpected line counts catch bugs early. - Prefer
rsync -avPovercpfor anything large or over a network - it resumes and shows progress.