mrkent mrkent - 3 months ago 8x
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.


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.