Reading files
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Reading a file
catprints a file's contents straight to the screen:
cat poem.txt
- It is named after "concatenate" — it can also join several files together.
Just the start or end
- For a long file you often want only a peek:
headshows the first lines,tailshows the last lines.
head -n 2 poem.txt
tail -n 1 poem.txt
- The
-noption chooses how many lines.
Counting
wc(word count) measures a file. The most useful option is-lfor lines:
wc -l poem.txt
wc -wcounts words andwc -ccounts characters. Now try the tasks.
Common mistakes
catprints a whole file at once; uselessto scroll a large one.- Press Tab to complete a long file name.
Use cat to print the whole contents of poem.txt.
How many lines does the poem have? Use wc -l poem.txt to count them.