cat (Unix)

Cat ( / bin / cat, / usr / bin / cat ) is a system program in Unix and Unix-like systems. It is used to merge files. The name derives from the English concatenate or its synonym catenate ( German: concatenate ) from.

Specification and Operation

The range of functions as well as the behavior of cat is determined both by the Single Unix Specification, as well as the POSIX standard.

Cats behavior with respect to signals, return values, and calling syntax is typical according to the standard for a command line program. One or more files whose names are passed as an argument is read and output in a coherent single data stream. It is prescribed in particular that files appear in that order in the output, in which they are passed as an argument. The output is always to stdout and can be redirected from there by the usual means ( Redirection, pipeline). As with many other UNIX system programs represents a single hyphen ("-" ) stdin as the file name.

Each file can be repeatedly passed as an argument. Then as many copies of its contents appear in the output. With the-u option unbuffered output can be enforced, which can be advantageous when it is read from the FIFO.

Use

Probably the most common use of the command cat - namely with a single file as an argument - is actually a misuse ( see below). Properly used, together cat files. Thus, it corresponds to the function of copy / b ... ... derived in MS- DOS systems or the type command on VMS, CP / M, MS- DOS, OS / 2 and Microsoft Windows.

This example returns the contents of the two specified files one by one ( only file1, file2 then ), then the related input from stdin. The output is a single stream of data from the three sources and the output redirection ensures that the result is stored in the file outfile.

# Cat / path/to/file1 / path/to/file2 -> / some / outfile See also: paste (Unix), split ( Unix) and join ( Unix)

There is a widespread misconception that cat is to be used for text files. Although the operation of the internationalization variables ( LANG, LC_ALL, etc.) is affected, the POSIX standard specifies, however, explicitly states that cat can handle any type of input file.

Extensions, variants

By way of derogation from the POSIX standard offer some cat implementations extensions of the initial functional scope. The cat version of the GNU initiative can spend about line numbers, rewrite, and the like, non-printable characters printable. The use of such extensions in scripts restricts their use to the possibility, however, they supportive platform with an origin, which is why this is generally regarded as a bad scripting style.

In particular, the -v option ( non-printable characters can be printed rewrite ) was the topic of the presentation UNIX style, or cat -v Considered harmful by Rob Pike at Usenix Summer Conference 1983. The lecture was written by one, together with Brian W. Kernighan Paper Program Design in the UNIX Environment accompanied, which led in turn to the Pike and Kernighan jointly authored standard work the UNIX Programming Environment.

Some utilities that provide functionality similar to cat take, by their names directly reference. zcat files are from a packed archive with gzip to stdout. tac operates as cat, but the files are from the rear to the front.

Unnecessary use, Useless Use

Because cat is the possibility to transfer a single file as an argument, it is often misused to output the contents of a file into a data stream. This false use is so widespread that it on Usenet (especially comp.unix. * And comp.os.unix. *) Has developed the concept useless use of cat (also short UUOC or variations thereof ). In fact, this procedure costs because of the additional necessary ( and in terms of resource consumption "expensive" ) system call fork () useless computation time, without any advantage to offer. Virtually all of these constructs can be mapped without a cat, as the following examples show using redirection:

Cat / path / to / file | grep "something" # useless use of cat grep "something" / path / to / file # correct call, file name as an argument cat / path / to / file | cmd arg1 arg2 # argN useless use of cat cmd arg1 arg2 argN

Reception in the Unix Culture

Based on the harmony of cat and " cat" ( cat) and based many ironic formulations: the already mentioned Demoggification or about when someone referred to as Herder of Useless Cats ( Shepherd useless cats).

The frequent misuse and the typical Unix utilities Spartan interface were often the target of a self-deprecating humor. The Jargon File says about in Lemma cat:

"Among Unix fans, cat (1 ) is Considered an excellent example of user - interface design, Because it delivers the file contents without seeking verbosity as spacing or headers in between the files, and does not require Because it the files to consist of lines of text, but works with any sort of data.

Among Unix haters, cat ( 1) Considered is the canonical example of bad user - interface design, its woefully unobvious Because of name. It is far more Often used to blast a file to standard output than to concatenate two files. The name cat for the former surgery is just as unintuitive as, say, LISP 's cdr. "

"Among Unix fans will cat (1 ) is considered as an excellent example of the design of a user interface, because it outputs the file contents without further talkativeness as separation distances or headers between the files, and also fails to files from text lines, but also any form of data cope.

On Unix - haters will cat (1 ) is considered as textbook example of bad design of the user interface because of its terribly misleading name. It is more often used to using a file to flood the standard output to merge two files. The name cat for the former of these activities was about as misleading as lisps cdr. "

History

A cat already existed in the AT & T Unix version 1 Who was the author is unknown, the manpage this was written by Dennis Ritchie.

170165
de