diff --git a/homepage/knowledge/cat.html b/homepage/knowledge/cat.html index 2e2f972..55de688 100644 --- a/homepage/knowledge/cat.html +++ b/homepage/knowledge/cat.html @@ -14,25 +14,36 @@ + +
-cat on a POSIX or otherwise UNIX-like system is a program that exists to concatenate files; to “join” one file at its end to another at its start, and output that resulting file to standard output.
-In practice this is usually accomplished by printing the contents of each sequential file argument to standard output.
+cat
on a POSIX or otherwise UNIX-like system is a program that exists to concatenate files; to “join” one file at its end to another at its start, and output that resulting file to standard output.
-cat was introduced in UNIX v1 to supercede the program pr which printed the contents of a single file to the screen (McIlroy); its first-edition manual page described cat as “about the easiest way to print a file” (“cat(1)”).
-cat’s modern, typical use is more or less the same; it’s often introduced to UNIX beginners as a method to print the contents of a file to the screen, which is why many implementations of cat include options that are technically redundant - see the often-included cat -e, -t, and -v that replace the ends of lines, tabs, and invisible characters respectively with printing portrayals (“cat(1p)”).
+cat
was introduced in UNIX v1 to supercede the program pr which printed the contents of a single file to the screen (McIlroy); its first-edition manual page described cat as “about the easiest way to print a file” (“cat(1)”).
+cat
’s modern, typical use is more or less the same; it’s often introduced to UNIX beginners as a method to print the contents of a file to the screen, which is why many implementations of cat
include options that are technically redundant - see the often-included cat
-e, -t, and -v that replace the ends of lines, tabs, and invisible characters respectively with printing portrayals (“cat(1p)”).
-The POSIX standard as of 2003 requires only the option -u to be implemented, which prevents cat from buffering its output - on some systems, cat buffers its output in 512-byte blocks (McIlroy), similarly to dd’s default as defined by POSIX (“dd(1p)”), though most currently popular cat implementations do this by default and ignore the -u flag altogether (busybox, GNU coreutils).
-POSIX doesn’t mandate buffering by default.
+The POSIX standard as of 2003 requires only the option -u
to be implemented, which prevents cat
from buffering its output - on some systems, cat
buffers its output in 512-byte blocks (McIlroy), similarly to dd
’s default as defined by POSIX (“dd(1p)”), though most currently popular cat
implementations do this by default and ignore the -u
flag altogether (busybox, GNU coreutils).
+POSIX doesn’t mandate buffering by default - specifically, -u
has to guarantee that the output is unbuffered, but cat
doesn't have to buffer it in the first place and can ignore -u
in that case.
-This is a POSIX-compliant implementation of UNIX cat with no additional features nor buffered output (it ignores cat -u
) in C:
+This is a POSIX-compliant implementation of UNIX cat with no additional features nor buffered output in C:
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -126,7 +137,7 @@ main(int argc, char *argv[]){
It’s worth noting that this concept of cat as a utility that sequentially prints given files to standard output means cat can be replaced by a simple shell script that does the same using dd and printf; cat as defined by POSIX is actually totally redundant to other POSIX utilities. Here’s the shell script:
-
+
#!/bin/sh
# some older systems will use the former POSIX_ME_HARDER rather than
@@ -204,9 +215,9 @@ exit 0
As of 2021-06-19 the publicly editable section reads: POSIX mandates 512-byte default block sizes for the df and du utilities, reflecting the typical size of blocks on disks. When Richard Stallman and the GNU team were implementing POSIX for the GNU operating system, they objected to this on the grounds that most people think in terms of 1024 byte (or 1 KiB) blocks. The environment variable POSIX_ME_HARDER was introduced to allow the user to force the standards-compliant behaviour. The variable name was later changed to POSIXLY_CORRECT. This variable is now also used for a number of other behaviour quirks.
-Common cat implementations