What is the use of "-u" option in cat command? [closed] What is the use of "-u" option in cat command? [closed] linux linux

What is the use of "-u" option in cat command? [closed]


Per the POSIX standard for cat:

SYNOPSIS

cat [-u] [file...]

...

OPTIONS

...

The following option shall be supported:

-uWrite bytes from the input file to the standard output without delay as each is read.

That could be implemented by disabling buffering on the output.


option -u disables buffering to stdout.

GNU documentation reads:

Use unbuffered I/O for stdout. Posix does not specify the behavior without this option.

which is perhaps indicating that the current default behavior of cat is to output without buffering.


The idea behind cat -u is indeed that the output should be unbuffered, so that even if cat is in a pipeline, the data will be written promptly as it is read.

It can matter when you use cat -u "$@" | … and the input is, in fact, coming from a keyboard.

The chances are that GNU cat effectively works without buffering (using direct read() and write() calls), so the -u option is irrelevant — it always works in 'unbuffered mode'.