Terminal Basics
Overview
Teaching: 0 min
Exercises: 35 minObjectives
Navigate the filesystem using
pwd,ls, andcdDistinguish absolute paths from relative paths
use command history and tab completion
combine commands using pipes
|and redirect output with>Create, copy, move, and rename files and directories using the terminal and via VS Code Explorer
View the contents of a file without opening an editor
Two ways to do (almost) everything
VS Code’s Explorer sidebar lets you browse, create, rename, and delete files and folders on Draco using your mouse or trackpad, much like Finder or File Explorer on your laptop. This is useful, but bioinformaticians often use the terminal instead. It is especially powerful for running programs, chaining commands together, working with many files at once, and submitting jobs to the cluster.
In this section we will give a brief introduction to using the terminal.
1. Where am I? What’s here?
The terminal always has a current working directory: the folder you are currently in. Two commands are particularly useful for finding your way around:
pwd # print working directory — "where am I right now?"
ls # list files and directories here
ls -l # list with more detail
pwd tells you where you are. ls shows you what is there. The -l option gives you additional information such as permissions, file size, and modification date.
Exercise 1
- Run
cd ~/Viromics2026_workspacethenpwdto confirm where you are.- Run
ls, thenls -l. What extra information does-lshow?- Run
ls data/sequences. How many files are in there?
Solution
ls -lshows one entry per line with permissions, ownership, file size, and last-modified date, This useful for checking whether a file is empty (size0) or when it was last touched.
2. Sorting by date
Sometimes you don’t want files in alphabetical order. Perhaps you want to know what file changed most recently.
ls -ltrh data/sequences
-l→ long format-t→ sort by modification time (newest first, by default)-r→ reverse the order (so with-t, this puts the oldest file first and the newest file last)-h→ human-readable file sizes (e.g.1.2Ginstead of1234567890)
Exercise 2
- Run
ls -lh data/sequences(no sorting) and note the order.- Run
ls -ltrh data/sequences. Did the order change?- Which file is listed last? What does that tell you?
Solution
Without
-t, files are listed alphabetically. With-ltrh, they’re listed oldest to newest, with the most recently modified file at the bottom. You will use this often once you’re creating your own results.
3. Moving around: absolute vs. relative paths
An absolute path always starts from the root of the filesystem (/). It works no matter where you currently are.
A relative path is interpreted starting from your current location.
cd /vast/groups/VEO # absolute — works from anywhere
cd ../ # relative — go up one directory
cd ./data/sequences # relative — go into a subfolder from here
cd ~ # shortcut for your home directory
cd - # jump back to the previous directory
Exercise 3
- From your home directory, move directly into
Viromics2026_workspace/data/sequencesusing one command.- Use
cd ..twice. Where are you now? Confirm withpwd.- Get back to
data/sequencesusing a relative path from where you are now.
Solution
cd ~/Viromics2026_workspace/data/sequences pwd cd ../.. pwd # ~/Viromics2026_workspace cd data/sequences pwd # back where you started
3. Don’t retype everything
The terminal keeps a history of the commands you have used.
Press the up arrow to recall your previous command. Keep pressing it to move further back through your history. The down arrow moves forward again. You can print a list of the full history with history.
You can also use Tab completion while typing. If you start typing a filename or directory name and press Tab, the terminal will complete the name when possible. This saves typing and helps avoid spelling mistakes.
For example, instead of typing the whole path: cd ~/Viromics2026_workspace/data/sequences, you can type part of it and press Tab to complete each directory name.
Exercise 3
- Type
pwd, then press the up arrow. What happens?- Press the up arrow again to find an earlier command.
- Navigate back to ~/Viromics2026_workspace using
cdand Tab completion rather than typing the entire path.
4. Combining commands
One of the most useful features of the terminal is that commands can be combined. The pipe (|) sends the output of one command directly to another command.
For example:
ls your/favourite/folder | wc -l
Here, ls produces a list of files, and wc -l counts the lines in that list.
You can also use > to save the output of a command to a file instead of displaying it on the screen:
ls your/favourite/folder > output_file.txt
The output is now stored in output_file.txt.
You can combine both:
ls your/favourite/folder | wc -l > output_file.txt
This lists the files, counts them, and saves the result to output_file.txt.
Be careful with >: if the file already exists, its contents will be replaced.
Exercise 4
- Use what you’ve just learned to count the number of sequencing files in
data/sequences.- Save the result to
sequence_file_count.txt.- Print the contents of the file you just created to the terminal using
cat sequence_file_count.txt.- Check the VS Code Explorer. Can you see the new file?
Solution
ls data/sequences | wc -l ls data/sequences | wc -l > sequence_file_count.txt cat sequence_file_count.txtThe first command displays the number of files in the terminal. The second saves that number to a file instead.
5. Creating, copying, moving, and deleting things
The terminal can also be used to manipulate files and directories.
mkdir my_folder # create a directory
cp file1.txt my_folder/ # copy a file into a directory
mv old_name.txt new_name.txt # rename (or move) a file
rm file.txt # delete a file — careful, there is no undo!
The same operations can be performed using the VS Code Explorer.
Exercise 5
- In
Viromics2026_workspace, create a folder calledday_01_terminal_practice.- Copy
sequence_file_count.txtinto it.- Inside
day_01_terminal_practice, rename the copy tosequence_file_count_backup.txt.- Now do the same kind of operation with the mouse: in the Explorer, copy
sequence_file_count.txt, paste it intoday_01_terminal_practice, and rename the pasted copy tosequence_file_count_backup2.txt.- Confirm that both files are there with:
ls -l day_01_terminal_practice
Solution
cd ~/Viromics2026_workspace mkdir day_01_terminal_practice cp sequence_file_count.txt day_01_terminal_practice/ cd day_01_terminal_practice mv sequence_file_count.txt sequence_file_count_backup.txt cd .. ls -l day_01_terminal_practice
Both approaches work on the same files. For a single file, the GUI is often just as convenient. Once you need to repeat an operation across dozens or hundreds of samples, however, the terminal becomes much more powerful.
You will use both approaches throughout the course. Use the GUI when it is convenient, and use the terminal when it gives you more control or saves you time.
Key Points
pwd, ls, and cd are the three commands you’ll use constantly to orient yourself
ls -ltrh sorts by modification time, oldest to newest, with human-readable sizes
The up/down arrow keys recall previous commands
Relative paths depend on where you currently are; absolute paths always start from /
mkdir, cp, mv, and rm manage files and directories. rm has no undo, use carefully