The time now is Sun 19 May 2013, 02:30
All times are UTC - 4 |
| Author |
Message |
tallboy

Joined: 21 Sep 2010 Posts: 343 Location: Oslo, Norway
|
Posted: Sat 09 Feb 2013, 13:38 Post subject:
Redirection with 'tee' - having your cake and eating it too. |
|
There is a very useful command named 'tee', that I don't see mentioned very often. I have gathered some info here.
Unix/Linux borrows an idea here from the plumbing trade. This is a redirection operator, but with a difference. Like the plumber's 'tee', it permits 'siphoning off' to a file the output of a command or commands within a pipe, but without affecting the result. This is useful for printing an ongoing process to a file or paper, perhaps to keep track of it for debugging purposes.
The `tee' command copies standard input to standard output and also to any files given as arguments. This is useful when you want not only to send some data down a pipe, but also to save a copy.
Synopsis: tee [OPTION]... [FILE]...
Examples:
| Code: | | cat listfile* | sort | tee check.file | uniq > result.file |
Here, the file 'check.file' contains the concatenated sorted "listfiles", before the duplicate lines are removed by uniq, and the result of that operation is sent to 'result.file'.
| Code: | | ls /root | tee my_directories.txt |
Lists the files (displays the output on the screen) and also sends the output to a file: 'my_directories.txt'. (puppy specific - the original would be /home/username instead of /root)
You can also write the output to multiple files as shown below.
| Code: | | ls | tee file1 file2 file3 |
Note:
- If a file being written to does not already exist, it is created.
- By default tee command overwrites the file.You can instruct the 'tee' command to append to the file using the option –a as shown below.
`-a' `--append' Append standard input to the given files rather than overwriting them.
tallboy
_________________ True freedom is a live Puppy on a multisession CD/DVD.
|
|
Back to top
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|
[ Time: 0.0358s ][ Queries: 11 (0.0036s) ][ GZIP on ] |