mrkent mrkent - 1 year ago 79
Linux Question

How to tail the last line of multiple files using "tail -1 */filename"

tail */filename

works, but

tail -1 */filename

doesn't. Why is this? And is there a 1 liner to perform this task without loops?

head -1 */filename

works for some strange reason.

Answer Source

Try this:

ls -1v --color=never */filename | xargs tail -n 1

This is using GNU ls.

Since the -v option is unique to GNU ls and not available in other utils it's easiest to use the output of ls directly as the "seed". Then we pipe it into xargs which builds the argument list in order it receives them from ls, and then runs tail on the whole thing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download