Cat (Unix)

Cat (Unix)

The cat command is a standard Unix program used to concatenate and display files. The name is from "", a synonym of concatenate.

Specification

The Single Unix Specification specifies the behavior that each of the files given in sequence as arguments will write their contents to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.

If the filename is specified as -, then cat will read from standard input at that point in the sequence. If no files are specified, cat will read from standard input.

Extensions

Both the BSD versions of cat (as per the OpenBSD manpage) and the GNU coreutils version of cat specify the following options:

* -b (GNU only: --number-nonblank), number non-blank output lines
* -n (GNU only: --number), number all output lines
* -s (GNU only: --squeeze-blank), squeeze multiple adjacent blank lines
* -v (GNU only: --show-nonprinting), displays nonprinting characters as if they were visible, except for tabs and the end of line character
* -t on BSD, -T on GNU, implies -v but also display tabs as ^I
* -e on BSD, -E on GNU, implies -v but also display end-of-line characters as $

Unix culture

Jargon File definition

The Jargon File version 4.4.7 lists this as the definition of cat:Quotation1
# 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.

Of such oppositions are holy wars made.... See also UUOC.

Useless use of cat

UUOC (from "comp.unix.shell" on Usenet) stands for "Useless Use of cat". As received wisdom on "comp.unix.shell" observes, "The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process." Nevertheless one sees people doing

cat "file" | "some_command and its args" ...

instead of the equivalent and cheaper

<"file" "some_command and its args" ...or (equivalently and more classically)

"some_command and its args" ... <"file"

Since 1995, occasional awards for UUOC have been given out, usually by Perl luminary Randal L. Schwartz. There is a web page devoted to this and other similar awards. In British hackerdom the activity of fixing instances of UUOC is sometimes called "demoggification".

Amongst the mildly paranoid it is still considered safer to use cat for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.

zcat

zcat is a UNIX program similar to cat, that decompresses individual files and concatenates them to standard output. Traditionally zcat operated on files compressed by compress but today it is usually able to operate on gzip or even bzip2 archives. On such systems, it's equivalent to gunzip -c. [http://www.freebsd.org/cgi/man.cgi?query=zcat&apropos=0&sektion=1&manpath=FreeBSD+7.0-RELEASE&format=html] zcat manual page in FreeBSD 7.0]

ee also

*Coreutils
*List of Unix utilities
*split, a command that splits a file into pieces which cat can then rejoin.
*tac, a similar tool which concatenates files backwards.
*type, the equivalent DOS, OS/2 and Microsoft Windows command.

External links

*man|cu|cat|SUS|concatenate and print files

Manual pages

*man/format|1|cat|http://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html|concatenate and write files|GNU Coreutils reference
*man|1|cat
*man|1|cat|Linux
*man|1|cat|OpenBSD|concatenate and print files
*man|1|cat|FreeBSD

Other

* [http://www.iki.fi/era/unix/award.html UUOC awards]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Cat (Unix) — Pour les articles homonymes, voir CAT. cat, qui vient de l anglais « catenate », synonyme de « concatenate » (soit : concaténer) est une commande Unix standard permettant de concaténer des fichiers ainsi que d afficher… …   Wikipédia en Français

  • Cat (Unix) — Saltar a navegación, búsqueda El comando cat (por concatenar) es un programa de Unix usado para concatenar y mostrar archivos. Contenido 1 Especificación 1.1 Extensiones 2 UUOC …   Wikipedia Español

  • Cat (Unix) — Das Unix Programm cat wird zum Anzeigen, Formatieren und Aneinanderhängen von Textdateien genutzt. Der Name cat leitet sich vom englischen concatenate bzw. dessen Synonym catenate (deutsch: aneinanderhängen) ab. Inhaltsverzeichnis 1 Spezifikation …   Deutsch Wikipedia

  • Cat (Unix) — cat es una instrucción de unix que concatena ficheros. Sintaxis: cat sin argumentos lee datos de la entrada estándar (stdin) y los escribe en la salida estandar (stdout). cat fichero1 fichero2 ... : saca por la salida estándar el contenido de… …   Enciclopedia Universal

  • cat (Unix) — Pour les articles homonymes, voir CAT. cat, qui vient de l anglais « catenate », synonyme de « concatenate » (soit : concaténer) est une commande Unix standard permettant de concaténer des fichiers ainsi que d afficher… …   Wikipédia en Français

  • Cat (UNIX) — …   Википедия

  • Cat (disambiguation) — A cat (Felis catus) , is a smaller, domesticated member of Felidae , the biological family of the cats. A cat can also refer to any member of the Felidae family.Cat may also refer to: * Cat (kingdom), a Dark Ages Pictish kingdom * Cat… …   Wikipedia

  • Unix — (registrado oficialmente como UNIX®) es un sistema operativo portable, multitarea y multiusuario; desarrollado, en principio, en 1969 por un grupo de empleados de los laboratorios Bell de AT T, entre los que figuran Ken Thompson, Dennis Ritchie y …   Wikipedia Español

  • UNIX-Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Befehle — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”