HP.
HP.

Reputation: 19896

Tail -f search file with * match and latest date time

I am trying to tail the latest file in a directory that matches a name.

Below example doesn't work

tail -f | ls -t /var/log/impala/impalad.demo.local.impala.log.INFO.* | head -1

tail: warning: following standard input indefinitely is ineffective
/var/log/impala/impalad.demo.local.impala.log.INFO.20180322-104843.43442

What is the best way to tail impalad.demo.local.impala.log.INFO.* that has latest time on it?

Upvotes: 2

Views: 347

Answers (1)

cadaniluk
cadaniluk

Reputation: 15229

Use

tail -f $(ls -t /var/log/impala/impalad.demo.local.impala.log.INFO.* | head -1)

instead. tail expects a file to read from, which you obtain with ls -t /var/log/impala/impalad.demo.local.impala.log.INFO.* | head -1. Piping follows an input | output pattern, though, so your current scheme won't get you far. Piping the filename into tail won't work either because tail doesn't expect filenames from standard input. To pass a filename to tail you must pass it as an argument.

Upvotes: 2

Related Questions