HOME

TheInfoList



OR:

cat is a
shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses Science Biology * Seashell, a hard outer layer of a marine ani ...
command for writing the content of a file or input stream to
standard output Standard may refer to: Symbols * Colours, standards and guidons, kinds of military signs * Standard (emblem), a type of a large symbol or emblem used for identification Norms, conventions or requirements * Standard (metrology), an object t ...
. The name is an abbreviation of ''concatenate'' which is from the Latin ''catenare'' meaning "to chain" Originally developed for
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
, it is available on many
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
s 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 re-directed, outputs file content on-screen.


History

cat was part of the early versions of
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
, e.g., Version 1. It replaced pr, a PDP-7 and
Multics Multics ("MULTiplexed Information and Computing Service") is an influential early time-sharing operating system based on the concept of a single-level memory.Dennis M. Ritchie, "The Evolution of the Unix Time-sharing System", Communications of t ...
command for copying a single file to the screen. It was written by
Ken Thompson Kenneth Lane Thompson (born February 4, 1943) is an American pioneer of computer science. Thompson worked at Bell Labs for most of his career where he designed and implemented the original Unix operating system. He also invented the B (programmi ...
and Dennis Ritchie. The implementation of cat bundled in GNU coreutils was written by Torbjorn Granlund and
Richard Stallman Richard Matthew Stallman ( ; born March 16, 1953), also known by his initials, rms, is an American free software movement activist and programmer. He campaigns for software to be distributed in such a manner that its users have the freedom to ...
. The
ReactOS ReactOS is a Free and open-source software, free and open-source operating system for i586/amd64 personal computers that is intended to be binary-code compatibility, binary-compatible with computer programs and device drivers developed for Wind ...
implementation was written by David Welch, Semyon Novikov, and Hermès Bélusca. Over time, alternative utilities such as tac and bat also became available, bringing different new features.


Use

The cat command can be used to serve various needs including but not limited to concatenation and display. A common use-case for concatenation is to specify multiple input files and to re-direct output to another file to persist the result. A common use-case for display is to specify a single file without re-directing output so that the file content displays on the monitor. Printing a single file to the monitor is a special use-case, yet it's the most common use. Many other scenarios can be supported by the command. The
Single Unix Specification The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
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, 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.GNU Coreutils
"GNU Coreutils manual"
'' GNU'', Retrieved on 1 Mars 2017.
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 In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
is: cat ptions ath... Options include: * (GNU: ), number non-blank output lines * implies but also display end-of-line characters as (GNU only: the same, but without implying ) * (GNU: ), number all output lines * (GNU: ), squeeze multiple adjacent blank lines * implies , but also display tabs as (GNU: the same, but without implying ) * use unbuffered I/O for stdout. POSIX does not specify the behavior without this option. * (GNU: ), 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 ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable character, printable and 33 control character, control c ...
. 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 Program stream (PS or MPEG-PS) is a container format (digital), container format for multiplexing digital audio, video and more. The PS format is specified in MPEG-1 Part 1 (ISO/IEC 11172-1) and MPEG-2 Part 1, Systems (ISO/IEC standard 13818-1/ITU ...
(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 The Jargon File is a glossary and usage dictionary of slang used by computer programmers. The original Jargon File was a collection of terms from technical cultures such as the MIT Computer Science and Artificial Intelligence Laboratory, MIT AI Lab ...
version 4.4.7 lists this as the definition of cat:


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 is sometimes called "cat abuse". Example of a common 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 Random access (also called direct access) is the ability to access an arbitrary element of a sequence in equal time or any datum from a population of addressable elements roughly as easily and efficiently as any other, no matter how many elemen ...
on the file, whereas the examples do not. This is because the redirection form opens the file as the stdin file descriptor which ''command'' can fully access, while the form simply provides the data as a stream of bytes. Another common case where 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 for a single file is to output the content of a file to standard output. However, if the output is piped or redirected, is unnecessary. A 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 with pipes. Compare: command < in , command2 > out <in command , command2 > out with: cat in , command , command2 > out


See also

* * * * * *


References


External links

*
UNIX Style, or cat -v Considered Harmful
- A paper by Rob Pike on proper Unix command design using cat as an example.
cat(1) original manual page
in the First Edition of
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
. * * * * * {{Core Utilities commands Unix text processing utilities Cat Unix SUS2008 utilities IBM i Qshell commands