Hands-on training for analysing Oxford Nanopore Technologies (ONT) sequencing data for microbial pathogen detection
This guide introduces essential Linux commands you’ll use throughout the bioinformatics training.
The command-line interface (CLI) allows you to interact with your computer by typing text commands instead of clicking icons. For bioinformatics, the CLI is:
When you open a terminal, you’ll see a prompt like:
username@hostname:~$
Breaking it down:
username: Your login namehostname: Computer name~: Current directory (~ means home directory)$: Regular user (# means root/admin)# Get help
command --help
# Get manual
man command
mkdir)# Create single directory
mkdir analysis
# Create multiple directories
mkdir data scripts results
# Create nested directories
mkdir -p analysis/qc/fastqc
# Create with specific permissions
mkdir -m 755 public_data
pwd)Shows your current location:
pwd
# Output: /home/username/projects
ls)# Basic listing
ls
# Long format (shows permissions, size, date)
ls -l
# Include hidden files (starting with .)
ls -a
# Human-readable sizes
ls -lh
# Sort by modification time (newest first)
ls -lt
# Reverse sort order
ls -ltr
# Commonly used combination
ls -lah
cd)# Go to home directory
cd
# or
cd ~
# Go to specific directory
cd /home/username/projects
# Go up one level
cd ..
# Go up two levels
cd ../..
# Go to previous directory
cd -
# Use relative paths
cd data/raw_reads
# Use absolute paths
cd /home/username/analysis/results
Path shortcuts:
~ = Home directory. = Current directory.. = Parent directory- = Previous directory/ = Root directorymkdir)# Create single directory
mkdir analysis
# Create multiple directories
mkdir data scripts results
# Create nested directories
mkdir -p analysis/qc/fastqc
# Create directory with multiple subdirectories in one command
mkdir -p data/{raw_reads,processed_reads,assemblies}
touch)# Create new file
touch sample_list.txt
# Update modification time of existing file
touch existing_file.txt
# Create multiple files
touch file1.txt file2.txt file3.txt
cp)# Copy file
cp source.txt destination.txt
# Copy file to directory
cp sample.fastq data/
# Copy directory recursively
cp -r analysis/ backup_analysis/
# Copy multiple files to directory
cp file1.txt file2.txt file3.txt destination_dir/
mv)# Rename file
mv old_name.txt new_name.txt
# Move file to directory
mv sample.fastq data/raw/
# Move multiple files
mv file1.txt file2.txt file3.txt destination/
# Move directory
mv old_dir/ new_location/
rm)# Remove file
rm file.txt
# Remove directory and contents
rm -r directory/
# Force remove (no confirmation)
rm -f file.txt
# Remove directory recursively, force
rm -rf directory/
⚠️ WARNING: rm is permanent! There’s no “Recycle Bin” in Linux.
cat)# Display file contents
cat file.txt
# Display with line numbers
cat -n file.txt
# Concatenate multiple files
cat file1.txt file2.txt > combined.txt
less)# Open file in pager
less large_file.txt
# Navigation in less:
# Space = next page
# b = previous page
# / = search forward
# ? = search backward
# q = quit
# g = go to start
# G = go to end
head/tail)# First 10 lines (default)
head file.txt
# First 20 lines
head -n 20 file.txt
# Last 10 lines
tail file.txt
# Last 50 lines
tail -n 50 file.txt
# Follow file in real-time (useful for logs)
tail -f logfile.txt
# Follow last 100 lines
tail -n 100 -f analysis.log
wc)# Count lines, words, characters
wc file.txt
# Count only lines
wc -l file.txt
# Count only words
wc -w file.txt
# Count characters
wc -c file.txt
# Count reads in FASTQ (lines/4)
echo $((`wc -l < sample.fastq`/4))
grep)# Search for pattern
grep "pattern" file.txt
# Case-insensitive search
grep -i "pattern" file.txt
# Show line numbers
grep -n "pattern" file.txt
# Count matching lines
grep -c "pattern" file.txt
# Invert match (show non-matching lines)
grep -v "pattern" file.txt
# Search recursively in directory
grep -r "pattern" directory/
# Search with regular expression
grep -E "pattern1|pattern2" file.txt
# Open file in nano
nano file.txt
# Keyboard shortcuts:
# Ctrl+O = Save
# Ctrl+X = Exit
# Ctrl+W = Search
# Ctrl+K = Cut line
# Ctrl+U = Paste
# Open file in vim
vim file.txt
# Basic commands:
# i = Enter insert mode
# Esc = Exit insert mode
# :w = Save
# :q = Quit
# :wq = Save and quit
# :q! = Quit without saving
# /pattern = Search
# List all processes
ps aux
# List your processes
ps -u username
# Real-time process viewer
top
# Better process viewer
htop
# Find specific process
ps aux | grep python
# Redirect output to file (overwrite)
command > output.txt
# Redirect output to file (append)
command >> output.txt
# Redirect error to file
command 2> error.txt
# Redirect both output and error
command > output.txt 2>&1
# or
command &> output.txt
|)# Chain commands
ls -l | grep ".fastq"
# Count files
ls | wc -l
# Sort and unique
cat file.txt | sort | uniq
# Search and count
grep "pattern" file.txt | wc -l
# Complex pipeline
cat sample.fastq | grep "^@" | wc -l
# Show command history
history
# Execute command from history
!123
# Execute previous command
!!
# Execute last command starting with 'cd'
!cd
# Search history
Ctrl+R, then type the search term
# Ctrl+C = Terminate current command
# Ctrl+Z = Suspend current command
# Ctrl+D = Exit shell (like 'exit')
# Ctrl+L = Clear terminal (like 'clear')
# Ctrl+W = Delete previous word
# Ctrl+Y = Paste deleted word
# Ctrl+R = Search command history
# tab = Auto-complete file/directory names
# tab twice = Show possible completions