read from standard input and write to standard output and files
add an example, a script, a trick and tips
Use netcat as a proxy to log traffic
Use socat, you don't need the pipes and fifos
How to combine the tee command with interactive scripts to log the results?
Use "script" - typescript of terminal session.
$ script --help
From the man page of
script makes a typescript of everything printed on your
terminal. It is useful for students who need a hard?
copy record of an interactive session as proof of an
assignment, as the typescript file can be printed out
later with lpr(1).
Alternative to the tee command without STDOUT
There is not directly a program to do that (this is pretty much
the only time that it would be useful), but you could easily
write your own. If you do not want to program, you could also
write a simple shell script that does the same thing:
> $1. This is different from putting it inline (as
sawdust suggested) because the sudo will apply to the entire
script, including the redirection.
Using tee to pipe ls and grep output into tail command without a script
had overread that you only want the last line of each
The command you need is
ls | grep '2011_.._.._.._35_.*' | xargs -n 1 -- tail -1
ls -1 2011_??_??_??_35_* | xargs -n 1 -- tail -1
This calls the command
tail -1 for each file that
grep command (1st case) or that is found
by the ls command (2nd case). Note that this will not work if a
file contains spaces or newline. If you need an answer for that
case, add a comment.
EDIT For your comment:
ls -1 2011_??_??_??_35_* | xargs -n 1 -I FILE -- sh -c 'echo ; echo "FILE"; tail -1 "FILE"'
A little bit more complicated, but also handles files with spaces
in the name.
"FILE" in the command sequence
echo "FILE"; tail -1 "FILE" will be replaced by a line
ls outputs. This command sequence will be
passed to a shell and then executed.
linux pipeline/tee process sequence
They will execute in parallel if they are capable of doing so.
tee command will feed input to both commands as
it gets it. This will make them "ready to run" if they were
blocked on input, and then the OS wills schedule them on whatever
cores it has available. This is not multithreading because that
takes place within a process. This is multiprocess operation.
input to each FILE, and also to standard output.
append to the given FILEs, do
ignore interrupt signals
display this help and exit
output version information and
If a FILE is
-, copy again to standard output.
Copyright © 2012 Free Software Foundation, Inc. License
GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute
it. There is NO WARRANTY, to the extent permitted by law.
Report tee bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page:
General help using GNU software:
Report tee translation bugs to
documentation for tee is maintained as a Texinfo
manual. If the info and tee programs are
properly installed at your site, the command
coreutils 'tee invocation'
should give you
access to the complete manual.
Written by Mike
Parker, Richard M. Stallman, and David MacKenzie.