Lesson 8 of 16 · 10 min
Inspecting sequence files in the shell
A sequence file can hold the DNA of an entire organism, so a single file might be several gigabytes in size. The shell, the text-based window where you type instructions to your computer, gives you safe ways to look inside such a file without ever loading the whole thing at once.
Why not a text editor
A text editor tries to read the entire file into memory before it shows you anything. That is fine for a small file, but a multi-gigabyte sequence file can freeze or crash your computer for several minutes while it struggles to load.
Warning: Never open a multi-gigabyte file in a text editor or by double-clicking it. The command cat prints a whole file to the screen, so use it only for small files of a few hundred lines. For anything large, reach for head, tail, or less instead.
Peek at the top
Sequence data often comes in FASTA format, a plain-text layout where each record starts with a header line beginning with a greater-than sign, followed by the sequence itself written as the letters A, C, G, and T (the four nucleotides, the chemical building blocks of DNA). The head command prints the first 10 lines of a file so you can check its format in an instant.
head reads.fasta>seq1 sample read
ACGTACGTACGTTGCAACGTAGCTAGCTAGCTAGCATCGATCGATCGTAGC
>seq2 sample read
TTGCATTGCAGCTAGCATCGATTACGATCGATCGTAGCTAGCTAGCTAGCA
>seq3 sample read
GATTACAGATTACAGATTACACGATCGATCGATCGTAGCTAGCTAGCTAGC
>seq4 sample read
CGTAGCTAGCATCGATCGATCGTAGCTACGATCGATCGATCGATCGTAGCT
>seq5 sample read
AACGTAGCTAGCTAGCATCGATCGATCGTAGCTAGCTAGCTAGCATCGATC
To choose how many lines you see, add -n followed by a number, as in head -n 4. The tail command works the same way but shows the last lines, which is handy for confirming a file finished writing. The command wc -l counts the total lines, and since each FASTA record here is two lines, dividing that count by two tells you how many sequences the file holds. To scroll through a huge file page by page, run less reads.fasta and press q to quit.
tail -n 2 reads.fasta
wc -l reads.fasta>seq50 sample read
ACGTAGCTAGCATCGATCGATCGTAGCTAGCTAGCATCGATCGATCGTAGC
100 reads.fasta
Try it yourself: Using the reads.fasta file from this lesson (or any FASTA file of your own), run head -n 8 reads.fasta to print its first 8 lines. You should see the first four records, each a header line plus one sequence line. Notice how quickly the command returns, even when the full file is enormous.