← Linux and the Command Line Lesson 5 of 51 · 10 XP

cat — the contents of files

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

cat (concatenate — "glue together") prints the contents of files:

cat notes.txt              # show a file
cat a.txt b.txt            # glue two files together in one output
cat -n notes.txt           # with line numbers

Together with redirection, cat creates and combines files:

cat a.txt b.txt > all.txt      # > — write the output to a file (overwrite it)
cat c.txt >> all.txt           # >> — append to the end

For big files cat is inconvenient: everything flies past on the screen. For viewing there's less, and for the start and the end of a file — head and tail.

You can quickly create a small file like this:

echo "the first line" > file.txt

Task. The starter code has created two files. Glue them together with cat into a new file all.txt (first part1.txt, then part2.txt), and then print all.txt with line numbers.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.