Command Line: Level 1 (Basics)

For complete beginners who have never opened a terminal. We start from what the command line even is, then build moving around, viewing files, searching, and the pipe, one small step at a time, with pictures.

🟢 Beginner ⏱️ ~2 hr 💻 Bash

Before you start

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.

You type a command then press Enter → The shell runs it carries out the task → You see the output printed back to you
The command line in one picture: a command in, a result out.

The parts of a command

Most commands have the same three parts. Knowing the names makes every example readable.

ls -l Downloads commandwhat to do optionhow to do it argumentwhat to act on
A command (what to do), an option that tweaks it (here, long listing), and an argument (the thing to act on).

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.

~ (home) project Downloads genes.fasta path to the file: ~/project/genes.fasta
~ 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.

cat seqs.fastaread the file | grep ">"keep header lines | wc -lcount them = count
Read the file, keep the header lines, count them. Each tool does one job; the pipe chains them into an analysis.
# "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
Try it: make a file with 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 -l or -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

pwdWhere am I?
ls / ls -lList files (with details)
cd folderMove into a folder (cd .. = up)
mkdir nameMake a folder
cp / mv / rmCopy / move-rename / delete
cat / head / tail / lessView a file's contents
grep "x" fileFind lines containing "x"
wc -l fileCount lines
cmd1 | cmd2Pipe: feed output into the next command
cmd > fileSave output to a file

Check yourself

Run each one in the practice terminal (or your own) and compare.

You typeYou should see
grep -c ">" seqs.fasta4 (the practice file has four sequences)
echo "ATGC" > dna.txt && cat dna.txtATGC
wc -l < reads.txt8 (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

What does ~ mean in a path?
Right. ~ is home, . is here, and .. is the folder above.
What is the difference between > and >> when saving output?
Correct. A single > replaces the file's contents; >> appends, leaving what was already there.
To count reads in a FASTQ file, a colleague runs grep ">" reads.fastq | wc -l and gets a number that is not the read count. Why is this wrong for FASTQ?
Correct. The > 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 )).
In ls -l Downloads, what is Downloads?
ls is the command, -l is the option, and Downloads is the argument (what to act on).
What does the pipe | do?
The pipe chains small tools together by passing output along, which is what makes the command line so powerful.

Sources & further reading

  1. 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.

Next in the Bash series

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).