On this page
Viewing and joining text
Much of the work at a command line is reading text — looking at a file, checking the start or end of one, pulling a column out, stitching two files together. This topic covers the commands for that: viewing files, showing parts of them, and joining or splitting text by line and by column.
This page is the map. The companion topic, Transforming text, covers the commands that reshape text — sorting, de-duplicating, substituting characters.
The commands
Viewing a whole file
| Command | Purpose |
|---|---|
cat |
Print one or more files straight through — and join several into one. |
tac |
Print a file with its lines in reverse — last line first. |
more |
Show a file one screen at a time, pausing between screens. |
Viewing part of a file
| Command | Purpose |
|---|---|
head |
Print the first lines (or bytes) of a file. |
tail |
Print the last lines of a file — and, with -f, keep printing as the file grows. |
nl |
Print a file with its lines numbered. |
Cutting and combining
| Command | Purpose |
|---|---|
cut |
Pull selected columns — byte ranges or delimited fields — out of each line. |
paste |
Join files side by side, line for line. |
join |
Join two files on a shared field, like a database join. |
comm |
Compare two sorted files and report which lines they share. |
Splitting a file into files
| Command | Purpose |
|---|---|
split |
Break a file into equal-sized pieces. |
csplit |
Break a file into pieces at lines that match a pattern. |
A note on input
Almost every command here follows the same convention for where its text comes from. Name one or more files and it reads those; name none and it reads from standard input, so it can sit in the middle of a pipeline. Where a command accepts files, the name - stands for standard input, so you can mix files and piped input in one invocation.
Where to start
To simply print a file, or join a few together, read cat — the most-used command in the topic.