shell: how to make tail of a file running in background shell: how to make tail of a file running in background shell shell

shell: how to make tail of a file running in background


You don't need tee at all for this, just use the shell's built-in append operator:

tail -f debug >> test.log &

The trailing & works as normal in the shell. You only need tee to send the output to a file as well as standard out, which if you have it in the background probably isn't what you want.


Normally you just use an ampersand after the command if you want to background something.

tail -f debug|tee -a test.log &

Then you can bring it back to the foreground later by typing fg. Did this answer your question or have I missed what you were asking?


The simple way to do this is:

screen -R -Dtail -f debug|tee -a test.logCtrl-A cps ax |grep tailCtrl-A [Backspace]...Ctrl-A [Spacebar]

screen lets you run multiple terminal sessions on one terminal connection. You switch back and forth with Ctrl-A [Backspace]|[Space]. To create another separate shell Ctrl-A c

A major benefit of screen is that if the terminal session disconnects, it keeps everything runnning. Just close the terminal window or disconnect ssh, go to another computer, log in and run screen -R -D to reconnect to everything which is still running.

If you only occasionally need this, just run tail, type Ctrl-Z, run a command, then fg %1 to bring the tail process back into the foreground, or bg %1 to make it run in the background permanently. If you do use Ctrl-Z, then the jobs command shows all of your detached jobs.