ArticleslgStudy

science

Cat (Unix)

Cat (Unix) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Cat (Unix) rather than just read about it. In short: cat is a shell command for writing the content of a file or input stream to standard output. The name is an abbreviation of catenate, a variant form of concatenate.

Cat (Unix) — main illustration
Cat (Unix) — illustration

Key takeaways

  • Cat (Unix) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Cat (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cat (Unix) from memory before moving on to harder problems.

Reference excerpt

cat is a shell command for writing the content of a file or input stream to standard output. The name is an abbreviation of catenate, a variant form of concatenate. Originally developed for Unix, it is available on many operating systems and shells today. In addition to combining files, cat is commonly used to copy files and in particular to copy a file to the terminal monitor. Unless redirected, cat outputs file content on-screen.

History cat was part of the early versions of Unix, e.g., Version 1. It replaced pr, a PDP-7 and Multics command for copying a single file to the screen. It was written by Ken Thompson and Dennis Ritchie. The implementation of cat bundled in GNU coreutils was written by Torbjorn Granlund and Richard Stallman.

Use The cat command can be used to serve various needs including concatenation and display. A use case for concatenation is to specify multiple input files and to redirect output to another file to persist the result. A common use case for display is to specify a single file without redirecting output so that the file content displays on the monitor. The Single Unix Specification defines the operation of cat to read files in the sequence given in its arguments, writing their contents to the standard output in the same sequence. The specification mandates the support of one option flag, -u for unbuffered output, meaning that each byte is written after it has been read. Some implementations, like GNU Core Utilities, do this by default and ignore the flag. If one of the input filenames is specified as a single hyphen (-), then cat reads from standard input at that point in the sequence. If no files are specified, cat reads from standard input only. The command-syntax is:

cat [options] [path...]

Options include:

-b (GNU: --number-nonblank), number non-blank output lines -e implies -v but also display end-of-line characters as $ (GNU only: -E the same, but without implying -v) -n (GNU: --number), number all output lines -s (GNU: --squeeze-blank), squeeze multiple adjacent blank lines -t implies -v, but also display tabs as ^I (GNU: -T the same, but without implying -v) -u use unbuffered I/O for stdout. POSIX does not specify the behavior without this option. -v (GNU: --show-nonprinting), displays nonprinting characters, except for tabs and the end of line character

Use cases cat can be used to pipe a file to a program that expects plain text or binary data on its input stream. cat does not destroy non-text bytes when concatenating and outputting. As such, its two main use cases are text files and certain format-compatible types of binary files. Concatenation of text is limited to text files using the same legacy encoding, such as ASCII. cat does not provide a way to concatenate Unicode text files that have a Byte Order Mark or files using different text encodings from each other. For many structured binary data sets, the resulting combined file may not be valid; for example, if a file has a unique header or footer, the result will spuriously duplicate these. However, for some multimedia digital container formats, the resulting file is valid, and so cat provides an effective means of appending files. Video streams can be a significant example of files that cat can concatenate without issue, e.g. the MPEG program stream (MPEG-1 and MPEG-2) and DV (Digital Video) formats, which are fundamentally simple streams of packets.

Examples

Unix culture

Jargon file definition The Jargon File version 4.4.7 lists this as the definition of cat:

# To spew an entire file to the screen or some other output sink without pause (syn. blast). By extension, to dump large amounts of data at an unprepared target or with no intention of browsing it carefully. Usage: considered silly. Rare outside Unix sites. See also dd, BLT. Among Unix fans, cat(1) is considered an excellent example of user-interface design, because it delivers the file contents without such verbosity as spacing or headers between the files, and because it does not require the files to consist of lines of text, but works with any sort of data.

Among Unix critics, cat(1) is considered the canonical example of bad user-interface design, because of its woefully unobvious name. It is far more often used to blast a single file to standard output than to concatenate two or more files. The name cat for the former operation is just as unintuitive as, say, LISP's cdr.

Useless use of cat Useless use of cat (UUOC) is common Unix jargon for command line constructs that provide only a function of convenience to the user. In computing, the word "abuse", in the sense of "improper or excessive use", is used to disparage the excessive or unnecessary use of a language construct; thus, abuse of cat is sometimes called "cat abuse". Example of a common cat abuse is:

cat filename | command arg1 arg2 argn

This can be rewritten using redirection of stdin instead, in either of the following forms (the first is more traditional):

command arg1 arg2 argn < filename

<filename command arg1 arg2 argn

Beyond other benefits, the input redirection forms allow command to perform random access on the file, whereas the cat examples do not. This is because the redirection form opens the file as the stdin file descriptor which command can fully access, while the cat form simply provides the data as a stream of bytes. Another common case where cat is unnecessary is where a command defaults to operating on stdin, but will read from a file, if the filename is given as an argument. This is the case for many common commands; the following examples

cat file | grep pattern

cat file | less

can instead be written as

grep pattern file

less file

A common interactive use of cat for a single file is to output the content of a file to standard output. However, if the output is piped or redirected, cat is unnecessary. A cat written with UUOC might still be preferred for readability reasons, as reading a piped stream left-to-right might be easier to conceptualize. Also, one wrong use of the redirection symbol > instead of < (often adjacent on keyboards) may permanently delete the content of a file, in other words clobbering, and one way to avoid this is to use cat with pipes. Compare:

command < in | command2 > out

<in command | command2 > out

with:

cat in | command | command2 > out

… excerpt ends here. Continue reading the full article.

Illustrations

Cat (Unix) illustration

Worked examples

Example 1 — a first encounter with Cat (Unix)

Start with the simplest possible case. Write down what Cat (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Cat (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Cat (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Cat (Unix)

In research
Cat (Unix) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Cat (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Cat (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics IBM i Qshell commands, Standard Unix programs, Unix SUS2008 utilities, so understanding it makes those chapters shorter.
In everyday life
Look for Cat (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Cat (Unix)” →

How to study Cat (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cat (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Cat (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cat (Unix) in simple terms?

cat is a shell command for writing the content of a file or input stream to standard output. The name is an abbreviation of catenate, a variant form of concatenate.

Why does Cat (Unix) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Cat (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Cat (Unix).

Tags

  • IBM i Qshell commands
  • Standard Unix programs
  • Unix SUS2008 utilities
  • Unix text processing utilities

Keep exploring