cat (Unix)
cat ( /bin/cat
, /usr/bin/cat
) is a system program in Unix and Unix - like systems. The name is derived from the English verb concatenate or its synonym catenate (in German, for example, 'to connect ', 'chain together', 'to chain'). cat reads the files specified as arguments and outputs the content to stdout
.
Specification and functionality
The scope of functions as well as the behavior of cat is determined by the Single UNIX Specification and the POSIX standard.
The behavior of cat
with regard to signals , return values and call syntax corresponds to the POSIX standard and is typical for a command line program. One or more files whose names are passed as an argument are read and output in a coherent single data stream. In particular, it is mandatory that files appear in the output in the order in which they are passed as arguments. The output is always made on stdout and can be redirected from there using the usual means ( redirection , pipeline ). As with many other Unix system programs, a single hyphen (“-”) filename represents stdin .
Each file can also be passed several times as an argument. Then just as many copies of its contents will appear in the output. The -u option can be used to force unbuffered output, which can be an advantage when reading from FIFOs.
use
Probably the most frequent use of the cat command - namely with a single file as an argument - is actually an abuse (see below ). Used correctly, cat merges files. It corresponds to the function of copy / b ... + ... in systems derived from MS-DOS or the command type under VMS , CP / M , MS-DOS, OS / 2 and Microsoft Windows .
The example outputs the content of the two specified files one after the other (first file1
, then file2
), then the -
input obtained from stdin (that's what this stands for ). The output is a uniform data stream fed one after the other from the three sources and the output redirection ensures that the result is outfile
stored in the file .
cat /path/to/file1 /path/to/file2 - > /some/outfile
See also: split (Unix) and join (Unix)
It is a common misconception that cat
text files should be used. The functionality is influenced by the internationalization variables (LANG, LC_ALL etc.), but the POSIX standard expressly specifies that cat
any form of input file can be processed.
Extensions, variants
In contrast to the POSIX standard, some cat
implementations offer extensions to the original range of functions. The cat
version of the GNU initiative, for example, can output line numbers, rewrite non-printable special characters in a printable manner and the like. The use of such extensions in scripts, however, restricts their use to the original platform that supports them, which is why this is generally regarded as a bad scripting style.
In particular, the -v option (rewrite non-printable characters as printable) was the topic of the presentation UNIX style, or cat -v considered harmful by Rob Pike at the Usenix Summer Conference 1983 . The lecture was accompanied by a paper program Design in the UNIX Environment , written jointly with Brian W. Kernighan , which in turn led to the standard work The UNIX Programming Environment jointly written by Pike and Kernighan .
Some utilities that cat
offer functions similar to these also refer directly to them by their names. zcat
outputs files from an archive packed with gzipstdout
. tac
works like cat
, but outputs the files from back to front.
Useless Use
Since it cat
is possible to pass a single file as an argument, it is often misused to output the content of a file as a data stream. This is bad style, however, as it is better to use a redirection ("<") or pass the file as an argument. This avoids unnecessary system calls fork()
and exec()
calls, cat
which would be necessary for calling . This usage is so widespread that the term useless use of cat (also UUOC or variations of it) has emerged on Usenet (especially comp.unix. * And comp.os.unix. * ) :
cat /path/to/file | grep "something" # useless use of cat
grep "something" /path/to/file # korrekter Aufruf, Dateiname als Argument
cat /path/to/file | cmd arg1 arg2 argN # useless use of cat
cmd arg1 arg2 argN < /path/to/file # korrekter Aufruf, Redirection
Mainly in the British hacker scene, the term demoggification for campaigns to eradicate such script errors is widespread, which is derived from the British slang expression moggy (further education of mongrel , mixed breed, without family tree) and describes a cat-promenade mixture . Demoggification is the removal of non-special cats .
Reception in the Unix Culture
Many ironic formulations were based on the consonance of cat and "cat" (cat): the already mentioned demoggification or, for example, when someone describes himself as the Herder of Useless Cats (shepherd of useless cats).
The frequent incorrect use and the spartan interface typical of Unix utilities were often the target of self-deprecating humor. The jargon file means in the Lemma cat:
"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 haters, 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 file to standard output than to concatenate two files. The name cat for the former operation is just as unintuitive as, say, LISP's cdr. "
"Among Unix fans, cat (1) is seen as an excellent example of the design of a user interface, because it outputs the file content without any further conversationalism such as separating spaces or headers between the individual files and does not consist of files made up of lines of text, but with any form of Data copes.
Unix haters consider cat (1) a textbook example of poor user interface design because of its terribly misleading name. It is used far more often to flood standard output with one file than to merge two files. The name cat for the former is about as misleading as LISP's cdr. "
history
A cat already existed in the AT&T -Unix Version 1. Who the author was is unknown, the manpage for it was written by Dennis Ritchie .
Individual evidence
- ↑ a b c d cat specification of the Open Group. Retrieved May 8, 2013 .
- ↑ POSIX chap. 12.2 Utility Syntax Guidelines. Retrieved October 3, 2016 .
- ^ Program Design in the UNIX Environment. Retrieved May 8, 2013 .
- ^ Brian W. Kernighan , Rob Pike : The UNIX Programming Environment Prentice-Hall Software Series, 1st ed. November 11, 1983, ISBN 013937681X .
- ^ Useless Use of Cat Award. (No longer available online.) Archived from the original on January 23, 2014 ; accessed on May 8, 2013 .
- ↑ User title "Herder of Useless Cats". Retrieved May 8, 2013 .
- ↑ The lemma "cat" in the Jargon File. Retrieved May 8, 2013 .
- ↑ cat (1) manpage from Mac OS X, 2004. Accessed May 8, 2013 (English).