2: Filesystem Hierarchy & Directory Operations
Chapter 2: Filesystem Hierarchy & Directory Operations
Unlike Windows, which assigns distinct drive letters (e.g., C:\, D:\) to physical disks, Linux organizes all storage devices into a single unified tree starting at the root directory (/). Understanding this directory hierarchy and mastering rapid path traversal is essential for organizing complex, multi-sample sequencing cohorts.
On supercomputing clusters, your home directory (/home/username) typically has strict storage quotas (e.g. 50 GB) intended only for scripts and config files. Raw sequencing datasets (FASTQ/BAM) must be stored in high-speed parallel scratch storage (e.g. /scratch/, /work/, or /nfs/) designed for high I/O throughput.
1. The Filesystem Hierarchy Standard (FHS)
/: The Root directory. The parent of all directories on the system./home/username: The user's personal home directory. Contains shell configuration files (.bashrc) and private documents. Abbreviated as~./etc: System-wide configuration files (networking, user accounts)./tmp: Ephemeral scratch space. Cleaned automatically upon reboot./opt: Third-party software packages and standalone bioinformatics binaries./var/log: Operating system and service log files.
2. Absolute vs. Relative Paths
Paths define the location of a file within the filesystem hierarchy:
- Absolute Path: Starts from the root directory (
/). Always points to the exact same file regardless of your current location (e.g.,/scratch/genomics/project1/sample_01.fastq.gz). - Relative Path: Defined relative to your current working directory (e.g.,
./data/sample_01.fastq.gzor../reference/genome.fa).
# Special path symbols:
. # Current working directory
.. # Parent directory (one level up)
~ # Current user's home directory
- # Previous working directory (toggle back)3. Directory Navigation & Inspection
# Print the current working directory
pwd
# Change into project directory
cd /scratch/genomics/project1
# Jump up one directory level
cd ..
# Jump back to your personal home directory
cd ~
# or simply:
cd
# Toggle back to the previous directory you were in
cd -
# List files with detailed metadata (permissions, owner, size, timestamp)
ls -la
# List files sorted by modification time (most recent at the bottom)
ls -lhtr
# Visualize directory tree structure up to 2 levels deep
tree -L 24. Directory Creation, Copying & Deletion
# Create nested project directories in a single command with -p (parents)
mkdir -p rnaseq_cohort/{raw_fastq,trimmed,alignments,feature_counts,reports}
# Copy files (use -r or -R for recursive directory copying)
cp sample1_R1.fastq.gz backup/
cp -r rnaseq_cohort/ rnaseq_cohort_backup/
# Move or rename files
mv old_name.fastq.gz sample01_R1.fastq.gz
mv *.bam alignments/
# Deletion commands (USE WITH EXTREME CAUTION - Linux rm has no Recycle Bin!)
rm temp_file.txt
rm -i cautious_delete.bam # Prompt before each deletion
rm -rf temporary_run/ # Force recursive deletion without confirmation5. Wildcard Expansion (Globbing) for NGS Samples
Bash shell wildcards allow you to batch-process dozens of sample files simultaneously without writing loops:
# Asterisk (*): Matches zero or more characters
ls *.fastq.gz # All compressed FASTQ files
ls sample_*_R1.fq.gz # Forward reads for all samples
# Question mark (?): Matches exactly one character
ls sample_??.bam # Matches sample_01.bam, sample_12.bam, but not sample_100.bam
# Character classes ([]): Matches any character enclosed
ls sample_[1-5]_R1.fastq.gz
# Brace expansion: Generates arbitrary combinations
touch sample_{A,B,C}_{R1,R2}.fastq.gz
# Creates: sample_A_R1, sample_A_R2, sample_B_R1, sample_B_R2, sample_C_R1, sample_C_R2Common Pitfalls & Troubleshooting Checklist
- Java Heap Exhaustion (GATK / Picard): If processes terminate with
java.lang.OutOfMemoryError, set your environment variable explicitly:export _JAVA_OPTIONS="-Xmx16g -Djava.io.tmpdir=/tmp". - Index Timestamp Mismatch: If tools complain that a BAM index is missing or out of date, regenerate with
samtools index -@ 4 sample.bam. - Conda Channel Conflicts: Avoid ABI incompatibilities between bioconda and conda-forge by setting strict priority:
conda config --set channel_priority strict. - Chromosome Naming Contamination: Always verify whether reference FASTA headers use
chr1or1; divergent naming causes silent alignment drops.