That message is output on stderr like all warning and error messages.
You can either drop all the error output:
tail -f file 2> /dev/null
Or to filter out only the error messages that contain truncate
:
{ tail -f file 2>&1 >&3 3>&- | grep -v truncated >&2 3>&-;} 3>&1
That means however that you lose the exit status of tail
. A few shells have a pipefail
option (enabled with set -o pipefail
) for that pipeline to report the exit status of tail
if it fails. zsh
and bash
can also report the status of individual components of the pipeline in their $pipestatus
/$PIPESTATUS
array.
With zsh
or bash
, you can use:
tail -f file 2> >(grep -v truncated >&2)
But beware that the grep
command is not waited for, so the error messages if any may end up being displayed after tail
exits and the shell has already started running the next command in the script.
In zsh
, you can address that by writing it:
{ tail -f file; } 2> >(grep -v truncated >&2)
That is discussed in the zsh
documentation at info zsh 'Process Substitution'
:
There is an additional problem with >(PROCESS)
; when this is attached to
an external command, the parent shell does not wait for PROCESS to
finish and hence an immediately following command cannot rely on the
results being complete. The problem and solution are the same as
described in the section MULTIOS in note Redirection::. Hence in a
simplified version of the example above:
paste <(cut -f1 FILE1) <(cut -f3 FILE2) > >(PROCESS)
(note that no MULTIOS are involved), PROCESS will be run asynchronously
as far as the parent shell is concerned. The workaround is:
{ paste <(cut -f1 FILE1) <(cut -f3 FILE2) } > >(PROCESS)
The extra processes here are spawned from the parent shell which will
wait for their completion.