Skip to content

Navigating the Filesystem

When you open a terminal, you are always “inside” a directory. Every command you run happens relative to that location. Knowing where you are and how to move around is the first skill you need.

pwd stands for “print working directory.” It shows the full path of where you currently are.

Terminal window
$ pwd
/home/user

When you first open a terminal, you start in your home directory. This is your personal space on the machine.

ls lists the contents of the current directory.

Terminal window
$ ls
Desktop Documents Downloads projects
Terminal window
# Long format: shows permissions, size, and modification date
$ ls -l
drwxr-xr-x 2 user user 4096 Mar 28 projects/
-rw-r--r-- 1 user user 240 Mar 28 samplesheet.csv
# Show hidden files (files starting with a dot)
$ ls -a
. .. .bashrc .ssh Desktop Documents
# Human-readable file sizes
$ ls -lh
-rw-r--r-- 1 user user 1.2G Mar 28 sample_R1.fastq.gz
# Combine options
$ ls -lah

The -l flag is the one you will use most. It shows who owns each file, how big it is, and when it was last modified.

cd stands for “change directory.”

Terminal window
# Move into a directory
$ cd projects
# Check where you are now
$ pwd
/home/user/projects
Terminal window
# Go up one level (to the parent directory)
$ cd ..
# Go up two levels
$ cd ../..
# Go back to your home directory (three ways)
$ cd
$ cd ~
$ cd /home/user

The .. shortcut means “one directory above.” The ~ shortcut means “my home directory.” You will use both constantly.

Terminal window
# Absolute path: starts from the root /
$ cd /home/user/projects/rnaseq
# Relative path: starts from where you are now
$ cd projects/rnaseq

An absolute path always starts with / and works no matter where you are. A relative path starts from your current directory. Both get you to the same place.

Linux organizes everything in a single tree starting from /, called the root. Here is a simplified view of what matters for bioinformatics work.

/
├── home/
│ └── user/ ← your home directory
│ ├── projects/
│ │ ├── rnaseq/
│ │ │ ├── data/
│ │ │ ├── results/
│ │ │ └── samplesheet.csv
│ │ └── chipseq/
│ └── software/
├── tmp/ ← temporary files, cleared on reboot
├── usr/
│ └── bin/ ← installed programs
└── var/
└── log/ ← system logs

You will spend most of your time inside /home/user/. System directories like /usr/ and /var/ matter less for daily work.

Terminal window
# Create a single directory
$ mkdir results
# Create nested directories (all at once)
$ mkdir -p projects/rnaseq/data
# Create multiple directories
$ mkdir data results figures

The -p flag is important. Without it, mkdir projects/rnaseq/data fails if projects/ or rnaseq/ do not exist yet. With -p, it creates every missing level.

Terminal window
# Remove an empty directory
$ rmdir old_results

rmdir only works on empty directories. This is a safety feature. To remove directories with files inside, you will learn about rm -r in the next page.

Press Tab to autocomplete file and directory names. This saves time and prevents typos.

Terminal window
# Type "cd pro" then press Tab
$ cd pro<Tab>
$ cd projects/
# If multiple matches exist, press Tab twice to see options
$ cd p<Tab><Tab>
projects/ papers/

Tab completion works with commands, file paths, and many program options. Get in the habit of using it for everything.

The tree command shows a visual overview of a directory. It is not installed by default but is very useful.

Terminal window
# Install tree
$ sudo apt install tree
# Show the structure of the current directory
$ tree
.
├── data
├── sample_R1.fastq.gz
└── sample_R2.fastq.gz
├── results
└── samplesheet.csv
# Limit depth
$ tree -L 2
# Show only directories
$ tree -d

tree is especially helpful when exploring a new project or checking the output of a pipeline.

When you know a file exists but cannot remember where it is, find will search for it.

Terminal window
# Find all .fastq.gz files under the current directory
$ find . -name "*.fastq.gz"
./data/sample_R1.fastq.gz
./data/sample_R2.fastq.gz
# Find all directories named "results"
$ find /home/user/projects -type d -name "results"
# Find files modified in the last 24 hours
$ find . -mtime -1

The first argument is where to start searching. The -name flag matches file names. The -type d flag limits results to directories.

Command What it does
pwd Print current directory
ls List contents
ls -lh List with details and readable sizes
ls -a List including hidden files
cd dir Move into a directory
cd .. Move up one level
cd ~ Go to home directory
mkdir -p path Create directories (including parents)
rmdir dir Remove an empty directory
tree -L 2 Show directory structure (2 levels deep)
find . -name "*.csv" Search for files by name

Now that you can move around the filesystem, the next page covers working with files: creating, copying, moving, and understanding permissions.