Section 1 of 10

1 Before you start

Before you begin, take a few minutes to check what you already know and how confident you feel. You will see the same questions again at the end of the module — this helps both you and us measure what you have learned. Click an option for every question and confidence rating, then click Next to continue.

Pre-test

Which command is best for a 50,000-line log file you want to scroll through?

Pre-test

How do you quit less and return to the shell?

Pre-test

Which command prints only the first 3 lines of a file?

Pre-test

wc -l cohort_2026.csv reports 201. The file has a header row. How many patient records does it contain?

Pre-test

You see a file called download.bin and have no idea what is in it. Which command tells you the file type?

Pre-test

Which command shows the LAST 10 lines of a file?

Pre-test

You want to watch a log file update live as new lines are added. Which command?

Pre-test

What does wc -w report?

Pre-confidence

I can choose between cat, less, head, and tail based on how big the file is.

Not at all confident
Fully confident
Pre-confidence

I can count the number of lines in a file from the terminal.

Not at all confident
Fully confident
Pre-confidence

I know what to type when I am stuck inside less.

Not at all confident
Fully confident
Section 2 of 10

2 Introduction

You have been moving files without looking inside them. This lesson is about peeking at file contents from the terminal - whether the file is two lines or two million. You will also learn a handful of inspection commands: how big is this file, what kind of file is it, how many lines.

  • Reading short files: cat.
  • Reading long files without flooding your screen: less.
  • Peeking at the top or bottom: head and tail.
  • Counting lines, words, and characters: wc.
  • Asking "what kind of file is this?": file.
Five shell commands answer escalating questions about a file (what kind, how big, just the edges, all of it, or paged), so you inspect before you commit to reading and pick the lightest tool for the job.
Five shell commands answer escalating questions about a file (what kind, how big, just the edges, all of it, or paged), so you inspect before you commit to reading and pick the lightest tool for the job.
Section 3 of 10

3 cat - Dump a Whole File

cat prints a file in one go. cat is right when the file is short - say fewer than 30 lines. It is wrong for a big file: if you cat a 10,000-line log, your terminal scrolls past everything in a fraction of a second.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ cat notes.txt
cat is the right tool only when a file is short enough to fit on screen; on a large file it prints everything instantly, so the start scrolls out of view and you are left seeing just the end.
cat is the right tool only when a file is short enough to fit on screen; on a large file it prints everything instantly, so the start scrolls out of view and you are left seeing just the end.

Besides, cat can also stick several files together by listing them as arguments. The name come from concatenate.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ cd vitals
$ cat patient_001.csv patient_002.csv > two_patients.csv
$ cat two_patients.csv
cat follows a single rule, print each file's contents in sequence, so handing it several files simply prints them back to back, and that ordered dump is all "concatenation" means.
cat follows a single rule, print each file's contents in sequence, so handing it several files simply prints them back to back, and that ordered dump is all "concatenation" means.
Section 4 of 10

4 less - Scroll Through a Long File

less opens the file in a pager - a little reader inside your terminal where you scroll, search, and quit. It loads instantly even for huge files because it only reads what fits on screen.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ less cohort_2026.csv

If you ever open less and cannot get out, q is the escape hatch. less -N shows line numbers, handy for config files and scripts.

less reads only the screenful you are currently looking at and slides that window over the file, which is why even a million-line file opens instantly and can jump straight to the end without ever loading the whole thing.
less reads only the screenful you are currently looking at and slides that window over the file, which is why even a million-line file opens instantly and can jump straight to the end without ever loading the whole thing.

There are other keywords that you may use to make browsing the file easier.

  • Space or Page Down - next page.
  • b or Page Up - previous page.
  • j and k - down and up one line.
  • g - jump to the top.
  • G - jump to the bottom.
  • /word - search forward; n for next match.
  • ?word - search backward.
  • q - quit.
Section 5 of 10

5 head and tail - Just the Edges

Often you just want a peek at the start or end. head prints the first 10 lines; tail prints the last 10.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ tail cohort_2026.csv
head and tail print only the first or last lines of a file, so you can inspect a large file's start or end without opening the whole thing.
head and tail print only the first or last lines of a file, so you can inspect a large file's start or end without opening the whole thing.

Both take -n to pick a different count:

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ head -n 5 cohort_2026.csv
$ tail -n 2 cohort_2026.csv

tail also has -f (follow). tail -f run.log keeps the file open and prints new lines as they appear - the standard way to watch a long-running job. Ctrl+C stops it.

Adding -f keeps tail attached to a file and prints new lines as they are written, so you can watch a running job's log live until you stop with Ctrl+C.
Adding -f keeps tail attached to a file and prints new lines as they are written, so you can watch a running job's log live until you stop with Ctrl+C.
Section 6 of 10

6 wc - Counting Lines, Words, and Characters

wc (word count) reports lines, words, and characters in that order:

$ wc cohort_2026.csv
  201 201  5127 cohort_2026.csv
  • wc -l - just the line count (the one you will want most often).
  • wc -w - just the word count.
  • wc -c - just the byte count.

wc -l answers "how many records are in this file". For a CSV with a header, remember to subtract one for the header.

$ wc -l cohort_2026.csv
201 cohort_2026.csv
# 200 patients plus a header row
Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ wc cohort_2026.csv
$ wc -l cohort_2026.csv
$ wc -l notes.txt
wc reports one body of text at three nested grain sizes (lines, then space-separated words, then individual bytes), and because a CSV's header is itself a line, the patient count is the line count minus one.
wc reports one body of text at three nested grain sizes (lines, then space-separated words, then individual bytes), and because a CSV's header is itself a line, the patient count is the line count minus one.
Section 7 of 10

7 file - What Kind of File Is This?

Filenames in Linux are just labels. The .txt at the end of notes.txt is a hint, not a fact - nothing stops anyone renaming an image to mystery.txt. To learn what a file actually contains, use file. It peeks at the first few bytes and tells you what it sees.

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ file cohort_2026.csv
$ file scripts
A file's extension is just a renamable label, so to know what a file truly is you run file.
A file's extension is just a renamable label, so to know what a file truly is you run file.

Useful when you download something with an ambiguous name and need to know whether to cat it, unpack it, or leave it alone.

Section 8 of 10

8 Putting It Together

These commands are the inspection toolkit. A typical workflow when you meet an unfamiliar file:

  • file the-thing - text, image, or compressed?
  • wc -l the-thing - how many lines?
  • head the-thing - what do the first few lines look like?
  • less the-thing - scroll through it if you want more.

Later lessons chain these with pipes, but on their own they cover most "what is in this file?" questions.

Section 9 of 10

9 Check your understanding

You have reached the end of the module. Try the same questions again — your answers here, paired with your pre-test answers, are how we measure what the module taught you. Answer every question and confidence rating, then click Submit and see results to view your score.

Post-test

Which command is best for a 50,000-line log file you want to scroll through?

Post-test

How do you quit less and return to the shell?

Post-test

Which command prints only the first 3 lines of a file?

Post-test

wc -l cohort_2026.csv reports 201. The file has a header row. How many patient records does it contain?

Post-test

You see a file called download.bin and have no idea what is in it. Which command tells you the file type?

Post-test

Which command shows the LAST 10 lines of a file?

Post-test

You want to watch a log file update live as new lines are added. Which command?

Post-test

What does wc -w report?

Post-confidence

I can choose between cat, less, head, and tail based on how big the file is.

Not at all confident
Fully confident
Post-confidence

I can count the number of lines in a file from the terminal.

Not at all confident
Fully confident
Post-confidence

I know what to type when I am stuck inside less.

Not at all confident
Fully confident
Section 10 of 10

10 Your results

Here is how your post-test answers compare with your pre-test answers. The pre/post pairing is the most reliable way to see what this module actually taught you.

Your score

Submit the post-test to see your results.

Muddiest point

What is the one thing from this module that is still unclear to you?

Rate this module

Overall, how would you rate this module?

How likely are you to recommend this module to a peer? (0 = not at all, 10 = extremely likely)