TEE(1P)

๐Ÿ’– TEE(1P) ๐Ÿ’–

okay bestie, so this one lives in the POSIX Programmer's Manual, and it's called tee. yes like the shirt. yes it's iconic. no cap.

๐ŸŒธ PROLOG ๐ŸŒธ

okay so heads up, this page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly it might not be implemented on Linux at all. tragic, I know.


โœจ NAME โœจ

tee โ€” duplicate standard input. that's it. that's the whole job. queen behavior.


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

tee [-ai] [file...]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so the tee utility shall copy standard input to standard output, making a copy in zero or more files. like, it's splitting the stream, main character energy fr fr. and here's the spicy part: tee shall not buffer output. nope. not doing it. not today.

if the -a option is not specified, output files shall be written (see Section 1.1.1.4, File Read, Write, and Creation).

lowkey obsessed with how short this description is. it knows what it is. ๐Ÿ’…

๐Ÿ’… OPTIONS ๐Ÿ’…

the tee utility shall conform to the Base Definitions volume of POSIX.1โ€2017, Section 12.2, Utility Syntax Guidelines. so like, it follows the rules, but make it fashion.

the following options shall be supported:

  • -a โ€” append the output to the files. (not overwrite. append. know the difference bestie ๐Ÿซถ)
  • -i โ€” ignore the SIGINT signal. so like, Ctrl-C can't touch this.

๐ŸŒˆ OPERANDS ๐ŸŒˆ

the following operands shall be supported:

  • file โ€” a pathname of an output file. and listen, if a file operand is '-', it shall refer to a file named -. implementations shall not treat it as meaning standard output. like, it's literally just a file whose name is a dash, don't be weird about it. processing of at least 13 file operands shall be supported. thirteen. that's the bar. slay.

๐Ÿ’œ STDIN ๐Ÿ’œ

the standard input can be of any type. no restrictions. it's giving fluid.

๐Ÿ“ INPUT FILES ๐Ÿ“

None.

๐Ÿงš ENVIRONMENT VARIABLES ๐Ÿงš

the following environment variables shall affect the execution of tee:

  • LANG โ€” provide a default value for the internationalization variables that are unset or null. (see the Base Definitions volume of POSIX.1โ€2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
  • LC_ALL โ€” if set to a non-empty string value, override the values of all the other internationalization variables. it's the boss of the group chat.
  • LC_CTYPE โ€” determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
  • LC_MESSAGES โ€” determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
  • NLSPATH โ€” determine the location of message catalogs for the processing of LC_MESSAGES.

โšก ASYNCHRONOUS EVENTS โšก

default, except that if the -i option was specified, SIGINT shall be ignored. so -i is basically a shield. ๐Ÿ›ก๏ธ

โญ STDOUT โญ

the standard output shall be a copy of the standard input. same stream, same vibe.

๐Ÿ’€ STDERR ๐Ÿ’€

the standard error shall be used only for diagnostic messages. only. for. diagnostics. it's not a hangout spot.

๐ŸŒธ OUTPUT FILES ๐ŸŒธ

if any file operands are specified, the standard input shall be copied to each named file.

๐Ÿฆ„ EXTENDED DESCRIPTION ๐Ÿฆ„

None. (iconic of it honestly)


๐Ÿ‘‘ EXIT STATUS ๐Ÿ‘‘

the following exit values shall be returned:

  • 0 โ€” the standard input was successfully copied to all output files. we ate. ๐ŸŽ‰
  • >0 โ€” an error occurred. ๐Ÿ˜ญ

๐Ÿšจ CONSEQUENCES OF ERRORS ๐Ÿšจ

okay so real talk. if a write to any successfully opened file operand fails, writes to other successfully opened file operands and standard output shall continue, but the exit status shall be non-zero. like, it keeps going, it just tells you something went wrong. otherwise, the default actions specified in Section 1.4, Utility Description Defaults apply.

the following sections are informative. (so like, they're the commentary track, not the law ๐Ÿ’…)

๐Ÿ’– APPLICATION USAGE ๐Ÿ’–

the tee utility is usually used in a pipeline, to make a copy of the output of some utility. classic pipeline move.

the file operand is technically optional, but tee is no more useful than cat when none is specified. ๐Ÿ˜ญ not the shade but also... it's true bestie. if you're not saving anything you're just cat with extra steps.


๐ŸŒŸ EXAMPLES ๐ŸŒŸ

save an unsorted intermediate form of the data in a pipeline:

... | tee unsorted | sort > sorted

like, you get the raw version AND the sorted version. both. you don't have to choose. that's the whole point. ๐Ÿซถ


๐Ÿง  RATIONALE ๐Ÿง 

the buffering requirement means that tee is not allowed to use ISO C standard fully buffered or line-buffered writes. it does not mean that tee has to do 1-byte reads followed by 1-byte writes. so like, calm down, nobody said byte-by-byte. ๐Ÿ’€

it should be noted that early versions of BSD ignore any invalid options and accept a single '-' as an alternative to -i. they also print a message if unable to open a file:

"tee: cannot access %s\n", <pathname>

historical implementations ignore write errors. this is explicitly not permitted by this volume of POSIX.1โ€2017. so don't do that. periodt.

some historical implementations use O_APPEND when providing append mode; others use the lseek() function to seek to the end-of-file after opening the file without O_APPEND. this volume of POSIX.1โ€2017 requires functionality equivalent to using O_APPEND; see Section 1.1.1.4, File Read, Write, and Creation.


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

None.


๐ŸŽ€ SEE ALSO ๐ŸŽ€

  • Chapter 1, Introduction, cat
  • the Base Definitions volume of POSIX.1โ€2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
  • the System Interfaces volume of POSIX.1โ€2017, lseek()

portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017 edition, from the TEE(1P) page โ€” ily, go pipe something into a file ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ๐Ÿ’…๐Ÿซถ

๐Ÿ“ฆ where this page comes from