Noel Yap
Noel Yap

Reputation: 19778

How to timeout a Bash command and count the number of lines emitted to stdout?

I'd like to do something like timeout 12s tail -f access.log | wc -l but I'm not seeing the output from wc. What needs to be done to be able to do this?

Upvotes: 7

Views: 425

Answers (1)

anubhava
anubhava

Reputation: 785146

Use --foreground option with timeout:

timeout --foreground 12s tail -f access.log | wc -l

As per man timeout:

--foreground   when not running timeout directly from a shell prompt,
               allow COMMAND to read from the TTY and get TTY signals;
               in this mode, children of COMMAND will not be timed out

Upvotes: 5

Related Questions