1. Understanding the Linux file system
Linux organises files and folders in a hierarchical
structure. Unlike Windows, which commonly uses drive
letters such as C: and D:, Linux starts its directory
structure from a single root directory represented by
/.
A simplified Linux directory structure looks like this:
/
├── home/
│ └── isra/
│ ├── Documents/
│ ├── Downloads/
│ └── Bioinformatics/
│
├── etc/
├── usr/
├── var/
└── tmp/
Some important directories:
/— the root directory./home/— contains users' home directories./usr/— contains many system programs and libraries./etc/— contains system configuration files./tmp/— temporary files.
For your everyday bioinformatics work, you will mostly interact with your home directory and your project folders.
2. Absolute and relative paths
A path describes the location of a file or directory. Linux uses two common types of paths.
Absolute path
An absolute path specifies the complete location of
a file or directory, starting from the root directory
/.
/home/isra/Bioinformatics/RNAseq_Project
This path identifies the same location regardless of your current working directory.
Relative path
A relative path specifies a location in relation to your current working directory.
For example, suppose your current location is:
/home/isra/Bioinformatics
You can enter your RNA-seq project using:
cd RNAseq_Project
You do not need to type the complete directory path. Linux interprets the command relative to your current location.
3. Navigating directories using cd
We introduced cd in Lesson 01.
Let's explore some additional ways to use it.
Move into a directory
cd Documents
Move one level backwards
cd ..
Move two levels backwards
cd ../..
Return to your home directory
cd ~
Return to your previous directory
cd -
The cd - command is particularly useful
when switching between two working directories.
4. Listing files and directories
The ls command displays the contents
of your current directory.
ls
Explore these useful variations:
ls -l
ls -lh
ls -a
ls -lt
ls -R
ls -l— detailed file listing.ls -lh— readable file sizes.ls -a— includes hidden files.ls -lt— sorts files by modification time.ls -R— lists directories recursively.
You can also list the contents of a different directory without entering it:
ls /home/isra/Documents
5. Creating and organising directories
A well-organised directory structure is important when working with sequencing datasets.
Let's create a project directory:
mkdir RNAseq_Project
cd RNAseq_Project
mkdir raw_data
mkdir trimmed_data
mkdir quality_control
mkdir assembly
mkdir quantification
mkdir differential_expression
mkdir scripts
mkdir results
Your project structure will look like this:
RNAseq_Project/
│
├── raw_data/
├── trimmed_data/
├── quality_control/
├── assembly/
├── quantification/
├── differential_expression/
├── scripts/
└── results/
This structure separates different stages of your analysis and makes it easier to locate files.
Create nested directories
You can create multiple levels of directories
using the -p option.
mkdir -p RNAseq_Project/results/MultiQC
The -p option creates missing parent
directories when necessary.
6. Copying and moving files
Bioinformatics workflows often involve copying datasets, moving analysis outputs and organising intermediate files.
Copy a file using cp
The cp command copies files.
cp notes.txt backup.txt
This creates a copy named backup.txt
while retaining the original file.
Copy a file into another directory
cp sample.fastq raw_data/
Copy an entire directory
cp -r RNAseq_Project RNAseq_Project_backup
The -r option copies directories
recursively, including their contents.
Move or rename a file using mv
The mv command moves files and directories.
It can also rename them.
mv notes.txt results/
Rename a file:
mv notes.txt project_notes.txt
7. Viewing file contents
You will frequently need to inspect text files, configuration files, scripts and bioinformatics output files.
Using cat
cat displays the contents of a file.
cat notes.txt
Using less
less allows you to navigate through
a file without printing everything at once.
less notes.txt
Inside less:
- Press
Spaceto move forward. - Press
bto move backwards. - Press
/to search for text. - Press
qto exit.
Using head and tail
These commands display the beginning and end of a file.
head notes.txt
tail notes.txt
Display the first or last 20 lines:
head -n 20 notes.txt
tail -n 20 notes.txt
These commands are especially useful for inspecting large text-based bioinformatics files.
8. Removing files and directories
Linux provides commands for deleting files and directories. Use them carefully because deletion may be permanent.
Remove a file
rm notes.txt
Remove an empty directory
rmdir empty_folder
Remove a directory and its contents
rm -r old_project
Be particularly careful with rm -r.
Always verify the directory name and location
before executing a deletion command.
9. Working with FASTQ files
Let's connect these commands to a real bioinformatics scenario.
Imagine that you have downloaded paired-end RNA-seq sequencing data.
Your files might look like this:
SRR123456_1.fastq.gz
SRR123456_2.fastq.gz
SRR123457_1.fastq.gz
SRR123457_2.fastq.gz
You want to organise these files inside a project directory.
First, create a directory:
mkdir -p RNAseq_Project/raw_data
Move into your project:
cd RNAseq_Project
Check your current location:
pwd
List your raw data directory:
ls raw_data/
This is the basic logic behind managing sequencing datasets before running tools such as FastQC, Fastp, Salmon or Trinity.
10. Quick command reference
| Command | Purpose |
|---|---|
pwd |
Displays the current directory. |
ls |
Lists files and directories. |
cd |
Changes directory. |
cd .. |
Moves one directory backwards. |
cd ~ |
Returns to the home directory. |
mkdir |
Creates a directory. |
cp |
Copies files. |
mv |
Moves or renames files. |
rm |
Removes files. |
cat |
Displays file contents. |
less |
Views files interactively. |
head |
Displays the beginning of a file. |
tail |
Displays the end of a file. |
11. Practice
Open your Ubuntu terminal and complete these tasks:
- Create a directory named
Linux_Practice. - Enter the directory using
cd. - Create three directories named
data,resultsandscripts. - Create a file named
notes.txt. - Copy the file into the
resultsdirectory. - Rename the copied file to
analysis_notes.txt. - Use
ls -Rto inspect your directory structure.