11/23/2023 0 Comments Cat eof teeBut if you also wanted to log the output to a file called logfile so you could inspect it, you could use foo | tee logfile | bar. For example, suppose you were piping the output of a command called foo to the input of a command called bar. The most common use of tee is to insert it into a pipeline with a single filename argument. tee x y reads its input, writes it to the file x and also to the file y, and also writes it to its own standard output. For example, tee x reads its input, writes it to the file x, and also writes it to its own standard output. This is to say that it functions like a T-junction-or, more precisely, N T-junctions where N is the number of output files whose names you pass to it. Tee copies the content of its standard input to all of its output files as well as its own standard output. (Another way of putting this is that, with no filenames, cat behaves like cat -, since cat, like various other commands, treats - specially and takes it to designate standard input.) tee Basically, that means it reads whatever is piped or redirected to it, or otherwise whatever is typed into a terminal. When you run cat with no filenames, it defaults to reading from its own standard input. When passed a single filename, it copies that file's contents to standard output and then, since it has no more arguments, stops. For example, cat x y outputs the contents of x followed by the contents of y. This is to say that it concatenates the files. catĬat copies the content of all its input files to standard output, one after the other. cat reads potentially many files and sends their output to one place, while tee reads one input and sends it to potentially many files. In general, they have almost opposite behavior. ![]() The reason cat and tee do the same thing without any arguments, but different things with filenames passed as arguments, can be discerned by considering the behavior of each. When you do pass the cat and tee commands filenames, they behave differently from one another, and you can even accidentally overwrite files and lose data by passing their names to tee when you meant to pass them to cat. That's what's happening in your example the commands have output redirections ( >) but no actual command-line arguments. Otherwise, using tee when you mean cat can overwrite files you meant to read, causing accidental data loss.Ĭat and tee behave alike when you don't give them any filenames. Only when you pass no filenames to them do they have the same effect. TL DR: cat reads from files whose names you pass it, but tee writes to them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |