tee
read from standard input and write to standard output and files
Synopsis
tee
[OPTION]... [FILE]...
add an example, a script, a trick and tips
examples
source
Use netcat as a proxy to log traffic
Use socat, you don't need the pipes and fifos
source
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
:
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).
source
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: cat
> $1
. This is different from putting it inline (as
sawdust suggested) because the sudo will apply to the entire
script, including the redirection.
source
Using tee to pipe ls and grep output into tail command without a script
REVISED!
had overread that you only want the last line of each
logfile ...
The command you need is xargs
not tee
:
ls | grep '2011_.._.._.._35_.*' | xargs -n 1 -- tail -1
or
ls -1 2011_??_??_??_35_* | xargs -n 1 -- tail -1
This calls the command tail -1
for each file that
passes the 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.
Each "FILE"
in the command sequence echo ;
echo "FILE"; tail -1 "FILE"
will be replaced by a line
that ls
outputs. This command sequence will be
passed to a shell and then executed.
source
linux pipeline/tee process sequence
They will execute in parallel if they are capable of doing so.
The 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.
description
Copy standard
input to each FILE, and also to standard output.
-a, --append
append to the given FILEs, do
not overwrite
-i,
--ignore-interrupts
ignore interrupt signals
--help
display this help and exit
--version
output version information and
exit
If a FILE is
-, copy again to standard output.
copyright
Copyright © 2012 Free Software Foundation, Inc. License GPLv3+:
GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute
it. There is NO WARRANTY, to the extent permitted by law.
reporting bugs
Report tee bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page:
<http://www.gnu.org/software/coreutils/>
General help using GNU software:
<http://www.gnu.org/gethelp/>
Report tee translation bugs to
<http://translationproject.org/team/>
see also
The full
documentation for tee is maintained as a Texinfo
manual. If the info and tee programs are
properly installed at your site, the command
info
coreutils 'tee invocation'
should give you
access to the complete manual.
author
Written by Mike
Parker, Richard M. Stallman, and David MacKenzie.