I am trying to redirect output of a command to a file. The command I am using (zypper) downloads packages from the internet. The command I am using is
zypper -x -n in geany >> log.txt
The command gradually prints output to the console. The problem I am facing is that the above command writes the command output all at once after the command finishes executing. How do I redirect the bash output as I get it onto the terminal, rather than writing all the command output at the end.
&>>FILE COMMAND
will append the output of COMMAND to FILE
In your case
If you want to pipe a command through a filter, you must assure that the command outputs to standard output (file descriptor 1) — if it outputs to standard error (file descriptor 2), you have to redirect the 2 to 1 before the pipe. Take into account that only stdout passed through a pipe.
So you have to do so:
If you want to grep the output and in the same keep it into a log file, you have to duplicate it with
tee, and use a filter like... | tee log-file | grep options