Originally Posted by rahulu123
Thank you for much needed information....
Now, what I actually want is to Append the file each time I run a command. I have already tried this but...
$ 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:
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:
ls > >(tee -a file)
tee -a file < <(ls)