| name | foundations-linux-fundamentals |
| description | Linux CLI basics: cp/mv/rm, grep/awk/find, pipes, chmod, gzip/tar, wget/scp/rsync, ps/kill. Use when writing a bash pipeline, inspecting FASTA/FASTQ/BAM/BED/VCF on a server, or filtering lines with grep/awk. |
| tool_type | bash |
| primary_tool | bash |
Linux Fundamentals for Bioinformatics
When to Use
- Writing or debugging a shell pipeline that processes FASTA/FASTQ/SAM/BAM/BED/VCF/GTF files.
- Navigating a remote server/cluster, moving/copying/deleting files, or setting up a project directory tree.
- Filtering, counting, or reformatting text files with
grep/awk/cut/sort/uniq instead of writing a script.
- Downloading reference genomes/annotations (
wget/curl) or syncing data to/from a remote host (scp/rsync).
- Diagnosing "permission denied", background job management, or disk/CPU/RAM usage on a shared machine.
Version Compatibility
Applies to any modern Linux distro with GNU coreutils/bash ≥4 (Ubuntu 20.04+, CentOS/Rocky 8+, most HPC clusters). awk examples assume GNU awk (gawk) or POSIX awk — both work for the patterns below. macOS BSD variants of sed/find differ slightly (e.g., sed -i '' needs an explicit empty arg) but are noted where relevant.
Prerequisites
- A terminal/SSH session; no packages to install (
gzip, grep, awk, find, wget/curl, rsync, tar are on virtually every Linux box; install rsync/htop via apt/yum if missing).
- Concept: shells expand wildcards/redirection before the command runs (see Pitfalls).
Navigation & File Operations
Goal: Move around the filesystem and manage bioinformatics project directories/files safely.
Approach: Use pwd/cd/ls to orient, mkdir -p with brace expansion to scaffold a project in one line, and cp -r/mv/rm -rf for file management (note rm has no undo).
pwd
ls -lah
cd -
mkdir -p RNA_Seq/{00_raw,01_qc,02_trimmed,03_aligned,04_counts,scripts,logs}
touch RNA_Seq/scripts/run_pipeline.sh
cp -r results_dir/ results_backup/
mv unaligned.bam aligned.bam
rm -rf tmp_dir/
zcat sample.fastq.gz | head -8
zgrep "PASS" variants.vcf.gz
head -n 4 reads.fastq
tail -f pipeline.log
wc -l reads.fastq
Pipes, grep, awk, and find
Goal: Chain small commands into a pipeline to filter/count/transform genomic text files without writing a script.
Approach: Redirect with >/>>/2>&1, pipe stdout with |, filter lines with grep, do column math with awk, and locate files by name/size/time with find.
grep -c "^>" proteins.fasta
zcat sample.fastq.gz | wc -l | awk '{print $1/4, "reads"}'
grep -v "^#" variants.vcf | cut -f1 | sort | uniq -c
cut -f1 regions.bed | sort | uniq -c | sort -rn
grep -c "^>" genome.fa
grep -v "^#" variants.vcf
grep -i -w "brca1" gencode.gtf
grep -B 1 "GAATTC" seqs.fasta
grep -n "ERROR" pipeline.log
awk -F'\t' '{print $1, $4, $5}' annotations.gtf
awk '($3 - $2) > 1000' regions.bed
awk '{sum += $4} END {print "Total reads:", sum}' counts.bed
awk -F regions.bed
find . -name - samtools index {} \;
find . -size +1G
find . -mtime -7 -name
find . -name | xargs -sh
Wildcards, Permissions, and Compression
Goal: Match groups of files, set/read executable permissions, and compress/download data efficiently.
Approach: Let the shell expand globs before the command sees them; use octal chmod codes for scripts; prefer gzip/zcat/zgrep over manual decompression; use wget -c/rsync -avz for large transfers that may be interrupted.
ls *.fastq.gz
ls sample_[123].bam
ls chr[0-9]*.fa
chmod +x run_pipeline.sh
chmod 755 run_pipeline.sh
gzip -k large_file.fastq
tar -czvf archive.tar.gz results/
tar -xzvf archive.tar.gz
tar -tvf archive.tar.gz
wget -c https://ftp.ensembl.org/path/to/genome.fa.gz
curl -L -O https://example.org/annotation.gtf.gz
rsync -avz local_results/ user@cluster:~/remote_results/
scp -r local_dir/ user@server:~/
Processes and Remote Sessions
Goal: Run long jobs in the background, monitor resource usage, and work on a remote server.
Approach: Append & to background a job, manage it with jobs/fg/bg/kill, and inspect system load before launching heavy alignments.
bwa mem ref.fa reads.fastq > aligned.sam &
jobs
kill %1
ps aux | grep bowtie2
top -u "$(whoami)"
free -h
nproc
df -h
du -sh results/
ssh user@cluster.university.edu
Bioinformatics File Formats
| Format | Extension | Content |
|---|
| FASTA | .fa, .fasta | Sequences (genome, protein) |
| FASTQ | .fq, .fastq.gz | Reads + quality scores (4 lines/read) |
| SAM/BAM | .sam, .bam | Alignments (BAM = binary SAM) |
| BED | .bed | Genomic intervals (0-based, half-open) |
| VCF | .vcf | Variant calls (1-based) |
| GFF/GTF | .gff, .gtf | Gene annotations (1-based) |
Vim Survival Guide
vim filename open file
i insert mode (type text)
Esc back to normal mode
:w save
:q quit
:wq save and quit
:q! quit without saving
/pattern search forward
n / N next / previous match
dd delete line
u undo
:%s/old/new/g replace all occurrences in file
Pitfalls
- Spaces around
= in Bash: var = value is wrong; var=value is right — the space makes Bash treat var as a command name.
rm is permanent: no trash bin. Double-check before rm -rf; never run rm -rf / or rm -rf ~.
- Pipes discard stderr:
cmd1 | cmd2 only passes stdout between commands. Add 2>&1 if you also need to capture/pipe error messages.
- Wildcards expand before the command runs:
rm *.fastq — the shell does the glob expansion, not rm. If nothing matches, most shells error ("no such file") rather than silently doing nothing.
- Relative vs. absolute paths: cron jobs and cluster submission scripts often run from an unexpected working directory — always use absolute paths in scripts.
- Compressed files: use
zcat/zgrep/zless on .gz files; decompressing a multi-GB FASTQ just to grep it wastes disk and time.
find -exec vs xargs: -exec cmd {} \; runs the command once per file (slow for thousands of files); find ... | xargs cmd batches arguments and is much faster for bulk operations.
See Also
bio-sequence-io-compressed-files — working with gzipped FASTA/FASTQ in Python (BioPython/gzip).
bio-workflow-management-snakemake-workflows — turning ad-hoc shell pipelines into reproducible workflows.
bio-genome-intervals-bed-file-basics — BED coordinate semantics referenced above.
bio-alignment-files-sam-bam-basics — SAM/BAM structure referenced above.