Suppress 'file truncated' messages when using tail

Bas Peeters

I'm tailing a log file using tail -f messages.log and this is part of the output:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Fusce eget tellus sit amet odio porttitor rhoncus. 
Donec consequat diam sit amet tellus viverra pellentesque. 
tail: messages.log: file truncated
Suspendisse at risus id neque pharetra finibus in facilisis ipsum.

It shows tail: messages.log: file truncated when the file gets truncated automatically and that's supposed to happen, but I just want tail to show me the output without this truncate message.

I've tried using tail -f messages.log | grep -v truncated but it shows me the message anyway.

Is there any method to suppress this message?

Stéphane Chazelas

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Tail -f breaks when file truncated

From Dev

Suppress bold when using "__"

From Dev

How to suppress warning messages when loading a library?

From Dev

How to suppress tar error messages in when piping

From Dev

Suppress tslint messages when 'ionic serve'

From Dev

URL truncated when using regex

From Dev

libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

From Dev

libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

From Dev

Suppress dialog when using VBA to save a macro containing Excel file (.xlsm) as a non macro containing file (.xlsx)

From Dev

Data truncated when trying to import CSV file

From Dev

How do I suppress error messages on file.delete?

From Dev

Suppress Cyrus SASL log messages in Apache log file

From Dev

How to suppress EOF when echoing messages to wall from a script

From Dev

Suppress extra messages on ansible assert when the assertion passed as ok?

From Dev

File sent using HttpPost corrupted and/or truncated

From Dev

Substring function not working when truncated using mysql

From Dev

How to suppress awk output when using FS?

From Dev

Suppress Messages from MPI

From Dev

suppress warning messages in gnupg

From Dev

Suppress duplicate messages in rsyslog?

From Dev

suppress error messages in protractor

From Dev

Using tail to follow daily log file in Bash

From Dev

Recursive call not in tail position when using for comprehensions

From Dev

Equivalent of 'clear' command when using tail -f

From Dev

Bash - stdout text gets truncated when redirected to a file

From Dev

ios uilabel tail truncated trailing dot color

From Dev

Influence of number of steps back when using truncated backpropagation through time

From Dev

"String or Binary Data Would be Truncated" Error when using Linq to SQL

From Dev

error_log message is truncated when using print_r

Related Related

  1. 1

    Tail -f breaks when file truncated

  2. 2

    Suppress bold when using "__"

  3. 3

    How to suppress warning messages when loading a library?

  4. 4

    How to suppress tar error messages in when piping

  5. 5

    Suppress tslint messages when 'ionic serve'

  6. 6

    URL truncated when using regex

  7. 7

    libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

  8. 8

    libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

  9. 9

    Suppress dialog when using VBA to save a macro containing Excel file (.xlsm) as a non macro containing file (.xlsx)

  10. 10

    Data truncated when trying to import CSV file

  11. 11

    How do I suppress error messages on file.delete?

  12. 12

    Suppress Cyrus SASL log messages in Apache log file

  13. 13

    How to suppress EOF when echoing messages to wall from a script

  14. 14

    Suppress extra messages on ansible assert when the assertion passed as ok?

  15. 15

    File sent using HttpPost corrupted and/or truncated

  16. 16

    Substring function not working when truncated using mysql

  17. 17

    How to suppress awk output when using FS?

  18. 18

    Suppress Messages from MPI

  19. 19

    suppress warning messages in gnupg

  20. 20

    Suppress duplicate messages in rsyslog?

  21. 21

    suppress error messages in protractor

  22. 22

    Using tail to follow daily log file in Bash

  23. 23

    Recursive call not in tail position when using for comprehensions

  24. 24

    Equivalent of 'clear' command when using tail -f

  25. 25

    Bash - stdout text gets truncated when redirected to a file

  26. 26

    ios uilabel tail truncated trailing dot color

  27. 27

    Influence of number of steps back when using truncated backpropagation through time

  28. 28

    "String or Binary Data Would be Truncated" Error when using Linq to SQL

  29. 29

    error_log message is truncated when using print_r

HotTag

Archive