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

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 (ls works, LS does not).

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

R and the terminal do not run in this page, so here is what correct output looks like. Type each one and compare.

You typeYou should see
grep -c ">" genes.fastathe number of sequences
echo "ATGC" > dna.txt && cat dna.txtATGC
wc -l < reads.fastqthe number of lines

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 0. Why is this wrong for FASTQ?
Correct. The > header is a FASTA thing. 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 grep ">" seqs.fasta | wc -l tell you?
Each sequence has one header line starting with >, so counting those lines counts the sequences.
What does the pipe | do?
The pipe chains small tools together by passing output along, which is what makes the command line so powerful.
Why prefer head or less over cat for big files?
Genomic files can be enormous. cat floods your screen; head shows the top and less lets you scroll.
Next in the Bash series, the payoff

Project: wrangle a real data file from the command line →

Ready for more? Command Line Level 2 (Intermediate) builds straight on this.