Before you start
- Have a working terminal first. If not, work through Setting Up a Terminal.
- Any term new? The Glossary has it.
Learning objectives
By the end of this lesson you will be able to: know where you are and move around the filesystem; create and handle files and folders; look inside and search files; and combine commands with the pipe.
Start here, even if you have never opened a terminal
This lesson assumes nothing. We will explain what the command line even is, then build up moving around, looking at files, searching, and the one idea (the pipe) that makes it powerful, with pictures. Type each command yourself; muscle memory is the whole game here. You cannot break anything by looking.
What is the command line?
The command line (also called the terminal or shell) is a place where you type commands as text instead of clicking buttons. You type a command, press Enter, and the computer does it and prints the result. It feels old-fashioned, but for data it is faster and far more powerful than a mouse.
The parts of a command
Most commands have the same three parts. Knowing the names makes every example readable.
Anything after a # is a comment; commands are case sensitive, so type them in lowercase (ls, not LS). On a Mac, run setopt interactivecomments once so lines with # comments work.
Practise right here
Every code box on this page has a Run button that sends it to a real Linux terminal running in your browser. Nothing to install, no account. Practice files are already loaded: seqs.fasta, genes.txt, names.txt, reads.txt and file.txt. You can also type your own commands in the terminal. (Press q to leave less.)
1. Knowing where you are and moving around
The terminal always sits "inside" one folder. Three commands are your eyes and feet.
pwd # print working directory: where am I? ls # list what is in this folder ls -l # list with details (size, date) cd Downloads # change directory into Downloads (a brand-new WSL home folder may not have one yet) cd .. # go up one level cd ~ # go to your home folder
Files live in a tree of folders. A path is the address of a file in that tree.
~ is your home folder, . means "here", and .. means "the folder above". Master these three and you will never get lost.2. Creating and handling files and folders
mkdir project # make a new folder cd project touch notes.txt # create an empty file cp notes.txt copy.txt # copy mv copy.txt final.txt # move OR rename rm final.txt # remove (careful: no recycle bin!)
rm is forever
The command line has no trash can. rm deletes immediately and permanently. Read the line twice before you run it, especially before rm -r (which deletes whole folders).
3. Looking inside files
cat file.txt # dump the whole file to the screen head file.txt # first 10 lines head -n 3 file.txt # first 3 lines tail file.txt # last 10 lines less file.txt # scroll a big file (press q to quit)
head and less matter hugely in bioinformatics, where a single file can be gigabytes. You never want to cat a whole genome to your screen.
4. Searching and counting
grep "TP53" genes.txt # print lines containing "TP53" grep -c ">" seqs.fasta # COUNT lines containing ">" wc -l file.txt # count lines in a file sort names.txt # sort lines alphabetically sort names.txt | uniq # sort, then remove duplicates
Why grep is a bioinformatics superpower
FASTA files mark each sequence with a header line starting >. So grep -c ">" instantly counts how many sequences are in a file of any size. Tiny command, huge time saver.
5. The pipe: the big idea
This is the concept that makes the command line powerful. The pipe | takes the output of one command and feeds it straight into the next, so small tools combine into something bigger.
# "Take the file, keep header lines, then count them" cat seqs.fasta | grep ">" | wc -l
6. Saving output to a file
grep ">" seqs.fasta > headers.txt # write results to a NEW file grep ">" seqs.fasta >> headers.txt # ADD to an existing file
echo "ATGC" > dna.txt, then read it back with cat dna.txt. You just created and read a file entirely from the keyboard.Every key word, in plain English
- command line / terminal / shell
- the place where you type text commands.
- command
- the word that says what to do (
ls,cd,grep). - option (flag)
- a tweak starting with
-, like-lor-c. - argument
- the thing a command acts on, usually a file or folder.
- directory
- another word for a folder.
- path
- the address of a file in the folder tree.
- ~ . ..
- home folder, here, the folder above.
- pipe (|)
- feeds one command's output into the next.
- > >>
- save output to a new file / add to a file.
- comment
- a note after
#that the shell ignores.
Your starter cheat sheet
| pwd | Where am I? |
| ls / ls -l | List files (with details) |
| cd folder | Move into a folder (cd .. = up) |
| mkdir name | Make a folder |
| cp / mv / rm | Copy / move-rename / delete |
| cat / head / tail / less | View a file's contents |
| grep "x" file | Find lines containing "x" |
| wc -l file | Count lines |
| cmd1 | cmd2 | Pipe: feed output into the next command |
| cmd > file | Save output to a file |
Check yourself
Run each one in the practice terminal (or your own) and compare.
| You type | You should see |
|---|---|
| grep -c ">" seqs.fasta | 4 (the practice file has four sequences) |
| echo "ATGC" > dna.txt && cat dna.txt | ATGC |
| wc -l < reads.txt | 8 (two reads, four lines each) |
Practice exercises
Open your terminal and try each one before you reveal the solution.
Exercise 1: find your feet. Print the folder you are in, list its contents with details, then move into a folder called project.
Show a worked solution
pwd ls -l cd project
Exercise 2: peek, do not dump. Show only the first 3 lines of reads.txt without printing the whole file.
Show a worked solution
head -n 3 reads.txt
Exercise 3: count sequences. Count how many sequences are in seqs.fasta, where every header line starts with >. Try it with a pipe too.
Show a worked solution
grep -c ">" seqs.fasta # or, with a pipe: cat seqs.fasta | grep ">" | wc -l
Exercise 4: save the result. Write just the header lines of seqs.fasta into a new file called headers.txt.
Show a worked solution
grep ">" seqs.fasta > headers.txt
Check your understanding
~ mean in a path?~ is home, . is here, and .. is the folder above.> and >> when saving output?> replaces the file's contents; >> appends, leaving what was already there.grep ">" reads.fastq | wc -l and gets a number that is not the read count. Why is this wrong for FASTQ?> header is a FASTA thing (and in FASTQ, > can even appear inside quality lines). FASTQ uses four lines per read, so the read count is $(( $(wc -l < reads.fastq) / 4 )).ls -l Downloads, what is Downloads?ls is the command, -l is the option, and Downloads is the argument (what to act on).| do?Sources & further reading
- Cock PJ, Fields CJ, Goto N, Heuer ML, Rice PM. The Sanger FASTQ file format for sequences with quality scores, and the Solexa/Illumina FASTQ variants. Nucleic Acids Research 38: 1767-1771, 2010. (why FASTQ has four lines per read) doi:10.1093/nar/gkp1137
Official documentation:
The Unix Shell, The Carpentries: swcarpentry.github.io.
Last reviewed: October 2026.
Command line intermediate (Level 2) →
Ready for more? Command Line Level 2 (Intermediate) builds straight on this.
Practice terminal powered by sandbox.bio (runs in your browser; your commands stay on your computer).
