cat
Files and directories
Usage
cat [file...]Prints files one after another; it dumps everything at once, so long files want less and cat file | grep is one pipe too many.
Common flags
| Flag | Meaning |
|---|---|
| -n | Number every line |
| -b | Number only the non-blank lines |
| -s | Squeeze runs of blank lines into one |
| -v | Show non-printing characters |
| -e | BSD: -v plus a $ at each line end; GNU spells this -A |
Examples
cat a.txt b.txt > all.txtJoins two files into one.
cat -n script.shPrints it with line numbers.
cat > note.txtTypes a new file from the keyboard until Ctrl-D.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does cat do?
Prints files one after another; it dumps everything at once, so long files want less and cat file | grep is one pipe too many.
Q. How do I type it?
cat [file...] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man cat. This command sits under Files and directories.
Related commands
man page: man cat