Essential Linux Commands Every NGS Bioinformatics Intern Must Know
Priyanka Bhore · · Updated
Next-generation sequencing (NGS) generates large amounts of biological data, and analysing this data requires more than just knowledge of bioinformatics tools. Researchers and bioinformatics professionals also need to understand how to work with files, directories, software and datasets efficiently.
Most bioinformatics tools, including FastQC, BWA, SAMtools, GATK and HISAT2, are commonly used through the Linux command line. This is why Linux is an essential skill for anyone starting a career in genomics or bioinformatics.
For beginners, the Linux terminal may initially look complicated. However, learning a set of commonly used commands can make it much easier to navigate directories, manage sequencing files, inspect data and execute analysis tools.
In this blog, we will explore the essential Linux commands for bioinformatics interns, with practical examples relevant to NGS data analysis.
Why Is Linux Important in Bioinformatics?
Linux is an operating system widely used in research laboratories, universities, high-performance computing (HPC) environments and cloud-based bioinformatics platforms.
Many bioinformatics tools are developed primarily for Linux environments because they support command-line execution, scripting and large-scale data processing.
Linux is particularly useful for:
- Managing large FASTQ, FASTA, BAM and VCF files.
- Running NGS analysis tools.
- Processing multiple samples.
- Automating repetitive analysis tasks.
- Working on remote servers and HPC clusters.
- Building reproducible bioinformatics workflows.
Understanding Linux basics in bioinformatics helps interns become more comfortable working with real sequencing datasets.
1. Understanding the Linux Terminal
The terminal is a text-based interface used to communicate with the operating system through commands.
Instead of opening folders and clicking on files, users can perform operations by entering commands.
For example:
pwd
Purpose: Displays the current working directory.
Example output:
/home/user/bioinformatics
This tells us that the user is currently working inside the bioinformatics directory.
Another useful command is:
whoami
Purpose: Displays the username of the currently logged-in user.
These commands help users understand where they are working and which account they are using.
2. Essential Linux Commands for File and Directory Management
During NGS analysis, interns regularly work with directories containing raw sequencing files, reference genomes, alignment files and analysis results.
The following commands help manage these files.
ls – List Files and Directories
ls
Displays the files and directories present in the current location.
Useful options:
- ls -l – Displays files in detailed format, including permissions, size and modification date.
- ls -h – Displays file sizes in a human-readable format when used with -l.
- ls -a – Displays hidden files and directories.
- ls -lh – Displays detailed file information with readable file sizes.
cd – Change Directory
cd NGS_project
Moves into the NGS_project directory.
Other examples:
cd ..
Moves one directory level up.
cd ~
Moves to the user's home directory.
mkdir – Create a Directory
mkdir RNAseq_analysis
Creates a new directory named RNAseq_analysis.
To create multiple nested directories:
mkdir -p project/raw_data project/results project/reports
The -p option creates parent directories when required and does not report an error if the directories already exist.
touch – Create an Empty File
touch sample_info.txt
Creates an empty file named sample_info.txt if it does not already exist.
cp – Copy Files
cp sample.fastq.gz backup/
Copies the sequencing file into the backup directory.
mv – Move or Rename Files
To move a file:
mv sample.fastq.gz raw_data/
To rename a file:
mv old_name.txt new_name.txt
rm – Remove Files
rm sample.txt
Removes the specified file.
To remove a directory and its contents:
rm -r old_folder/
Important: The rm command permanently removes files in the usual Linux environment. Always verify the path before using it, particularly with recursive deletion options.
3. Commands for Viewing and Inspecting Genomic Data
Bioinformatics interns frequently need to inspect files before performing downstream analysis. For example, they may want to check FASTQ records, examine a sample information file or view the first few lines of a VCF file.
These commands are especially useful.
cat – Display File Contents
cat sample_info.txt
Displays the complete contents of the file.
It is useful for small text files, but displaying a very large file may fill the terminal with unnecessary output.
head – Display the First Few Lines
head sample.vcf
Displays the first 10 lines by default.
To display the first five lines:
head -n 5 sample.vcf
tail – Display the Last Few Lines
tail sample.vcf
Displays the last 10 lines by default.
To display the last 20 lines:
tail -n 20 sample.vcf
It is also useful for monitoring log files while a program is running:
tail -f analysis.log
The -f option continuously displays new lines added to the file.
less – View Large Files
less sample.vcf
Opens the file in a scrollable viewer without printing the entire content at once.
Useful controls:
- Arrow keys – Move up and down.
- Space – Move forward one screen.
- /pattern – Search for a particular word or pattern.
- q – Exit the viewer.
wc – Count Lines, Words and Characters
wc -l sample.vcf
Counts the number of lines in the VCF file.
Other options:
- -w – Counts words.
- -c – Counts bytes.
- -l – Counts lines.
For example, counting lines in a FASTQ file can provide a quick estimate of its size. Since each standard FASTQ read normally occupies four lines, the total number of reads can be estimated by dividing the line count by four. This assumes the file contains complete, standard FASTQ records.
4. Commands for Searching and Filtering Genomic Data
NGS datasets often contain thousands or millions of records. Searching for a particular gene, sequence identifier or variant manually is not practical.
Linux provides commands that make searching and filtering easier.
grep – Search for Specific Text
grep "BRCA1" genes.txt
Searches for lines containing BRCA1.
Useful options:
- -i – Ignores uppercase and lowercase differences.
- -n – Displays line numbers.
- -v – Displays lines that do not match the pattern.
- -c – Counts matching lines.
- -r – Searches recursively through directories.
Example:
grep -i "BRCA1" annotation.txt
This searches for BRCA1 without considering letter case.
cut – Extract Specific Columns
cut -f1,2 variants.tsv
Extracts the first and second tab-separated columns from the file.
For a comma-separated file:
cut -d',' -f1,3 samples.csv
Here:
- -d',' specifies the comma delimiter.
- -f1,3 extracts columns 1 and 3.
sort – Sort Data
sort genes.txt
Sorts the lines alphabetically.
Useful options:
- -n – Sorts numerically.
- -r – Sorts in reverse order.
- -k – Sorts based on a specified field.
uniq – Identify Unique Lines
sort genes.txt | uniq
Displays unique lines after sorting.
To count how many times each line occurs:
sort genes.txt | uniq -c
This can help summarize repeated gene identifiers or other categorical information.
awk – Process Structured Text Files
awk is a powerful command for extracting and processing columns from text-based files.
Example:
awk '{print $1, $2}' variants.tsv
Prints the first and second columns.
To print records where the fifth column contains a value greater than 30:
awk '$5 > 30 {print $1, $2, $5}' variants.tsv
This type of filtering is useful when working with tabular genomic data.
Note: These examples assume whitespace-separated or tab-separated data. For real VCF files, remember that header lines start with #, and the meaning of each column should be checked before filtering.
5. Commands for Managing Compressed NGS Files
NGS data files can be very large, so they are commonly stored in compressed formats such as .gz.
Linux provides several commands to work with compressed files.
gzip – Compress Files
gzip sample.fastq
Compresses the FASTQ file and produces sample.fastq.gz.
gunzip – Decompress Files
gunzip sample.fastq.gz
Decompresses the file.
zcat – View Compressed Files
zcat sample.fastq.gz | head
Displays the first few lines of a compressed FASTQ file without extracting the complete file.
zgrep – Search Compressed Files
zgrep "BRCA1" annotation.txt.gz
Searches for the specified text directly inside a compressed file.
These commands are particularly useful when working with large sequencing datasets that are stored in compressed form.
6. Commands for Working with NGS Analysis Tools
Most bioinformatics software is executed using command-line instructions. Interns should understand how to check software installations and execute basic commands.
which – Locate an Installed Program
which fastqc
Displays the location of the FastQC executable if it is available in the system's PATH.
--version – Check Software Version
fastqc --version
Displays the installed FastQC version.
Version checking is important because different software versions may produce different results or support different options.
Running a Basic FastQC Command
fastqc sample.fastq.gz -o results/
This command performs quality control on the FASTQ file.
- fastqc – Runs the FastQC program.
- sample.fastq.gz – Specifies the input sequencing file.
- -o results/ – Specifies the output directory.
Running BWA for Read Alignment
bwa mem reference.fa sample_R1.fastq.gz sample_R2.fastq.gz
Uses BWA-MEM to align paired-end sequencing reads against a reference genome.
- bwa mem – Selects the BWA-MEM alignment algorithm.
- reference.fa – Reference genome.
- sample_R1.fastq.gz – Forward reads.
- sample_R2.fastq.gz – Reverse reads.
The command writes SAM alignment data to standard output by default. In a complete workflow, this output is generally redirected or piped into SAMtools for further processing.
Running SAMtools
samtools view -bS sample.sam -o sample.bam
Converts a SAM file into BAM format.
- view – Reads and converts alignment files.
- -b – Produces BAM output.
- -S – Indicates SAM input; this option is generally unnecessary in modern SAMtools versions.
- -o – Specifies the output filename.
Understanding how to execute tools from the Linux terminal is an important part of command line NGS analysis.
7. Linux Commands for Monitoring Processes and Disk Space
NGS analysis can consume significant system resources. Some tools may take several hours to complete, especially when processing large sequencing datasets.
Interns should know how to monitor running processes and available storage.
top – Monitor Running Processes
top
Displays active processes and system resource usage, including CPU and memory.
ps – View Running Processes
ps aux
Displays information about running processes.
To search for a particular program:
ps aux | grep fastqc
df – Check Disk Space
df -h
Displays available and used disk space in a human-readable format.
du – Check Directory Size
du -sh results/
Displays the total size of the results directory.
These commands help identify storage or resource-related problems during genomic data analysis.
8. Understanding Pipes and Redirection in Linux
One of the most important concepts in Linux is the ability to connect commands together.
Pipe (|)
A pipe sends the output of one command as input to another command.
Example:
cat genes.txt | sort | uniq
This command:
- Reads the contents of genes.txt.
- Sorts the lines.
- Removes duplicate consecutive lines after sorting.
The pipe symbol allows multiple commands to work together without creating separate intermediate files.
Output Redirection (>)
ls > file_list.txt
Saves the output of the ls command into file_list.txt.
If the file already exists, its previous contents are overwritten.
Append Output (>>)
echo "Analysis completed" >> log.txt
Adds a new line to the end of log.txt without removing its existing contents.
Pipes and redirection are widely used when creating shell scripts and automating bioinformatics workflows.
9. Introduction to Shell Scripting for Genomics
Learning individual Linux commands is useful, but shell scripting allows interns to combine multiple commands into a single executable script.
For example, imagine processing multiple FASTQ files with FastQC. Instead of executing the command separately for every sample, a simple shell script can automate the task.
Example:
#!/bin/bash
mkdir -p fastqc_results
for file in *.fastq.gz
do
fastqc "$file" -o fastqc_results
done
echo "Quality control completed."
Understanding the script:
- #!/bin/bash – Specifies that the script should run using Bash.
- mkdir -p fastqc_results – Creates the output directory if it does not exist.
- for file in *.fastq.gz – Loops through all matching compressed FASTQ files.
- do – Starts the commands inside the loop.
- fastqc "$file" -o fastqc_results – Runs FastQC on each file.
- done – Ends the loop.
- echo – Displays a completion message.
Save the script as run_fastqc.sh.
To execute it:
bash run_fastqc.sh
This is a basic example of shell scripting for genomics. More advanced scripts can include error handling, sample-specific output directories, logging and automated execution of multiple NGS tools.
10. Essential Linux Commands: Quick Revision
The following commands are worth practising regularly when starting a bioinformatics internship.
| Command | Purpose |
| pwd | Display current directory |
| ls | List files and directories |
| cd | Change directory |
| mkdir | Create a directory |
| touch | Create an empty file |
| cp | Copy files |
| mv | Move or rename files |
| rm | Remove files or directories |
| cat | Display file contents |
| head | Display the first few lines |
| tail | Display the last few lines |
| less | View large files |
| wc | Count lines, words or bytes |
| grep | Search for text |
| cut | Extract columns |
| sort | Sort data |
| uniq | Identify unique lines |
| awk | Process structured text |
| gzip | Compress files |
| gunzip | Decompress files |
| which | Locate an executable |
| df -h | Check disk space |
| du -sh | Check directory size |
| top | Monitor system resources |
Conclusion
Linux is one of the fundamental skills every aspiring bioinformatics professional should develop. From managing sequencing files and inspecting genomic data to executing NGS tools and automating workflows, Linux commands are used throughout the bioinformatics analysis process.
For beginners, the best approach is to start with basic file management commands, gradually learn text-processing operations, and then practise running tools such as FastQC, BWA and SAMtools.
Once these commands become familiar, learning shell scripting and building automated analysis workflows becomes much easier.
A strong understanding of Linux, combined with practical experience in NGS tools and genomic data analysis, can help bioinformatics interns become more confident and productive when working on real-world research projects.