BASH: How to Redirect Output to File, AND Still Have it on Screen
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
drf@maplepark ~]$ echo 'Output from echo' >archivefile
[drf@maplepark ~]$ echo 'Output from subsequent file run' |tee -a archivefile
Output from subsequent file run
[drf@maplepark ~]$ cat archivefile
Output from echo
Output from subsequent file run
[drf@maplepark ~]$
Last edited by david1941; 04-02-2011 at 02:43 PM.
Reason: fix code tags
Now, what I actually want is to Append the file each time I run a command. I have already tried this but...
Code:
$ ls >> file |tee file
This is more complicated than it looks at the first glance and you should check man bash to understand better how it works. First, | "assigns" stdout of ls to stdin of tee (see "pipeline" and then "redirection" in man bash). Then, stdout of ls is "assigned" to file (leaving stdin of tee with no input at all), so ls fills file with the list of files. Then, stdout of tee is copied to file, too. Tee receives nothing on its stdin, so it writes an empty file over file before you get any chance to read the file file.
You may want to try:
Code:
ls | tee -a file
if you want to append the list of files to file and to display it on screen at the same time.
If you have nothing better to do, you can also have fun with:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.