V
V
v7resspect2019-02-12 12:39:54
linux
v7resspect, 2019-02-12 12:39:54

How to display the last lines of several files in one command in Linux?

Good day to all.
Task: print the last 5 lines from several files.
I output like this:

tail -5 "/path/to/file1.ext" && tail -5 "/path/to/file2.ext" && tail -5 "/path/to/file3.ext"

Problem: If file 2 does not exist, lines of subsequent files are not output.
Question: how can I print the last 5 lines of each file, skipping non-existent ones?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pfg21, 2019-02-12
@v7resspect

instead of "&&" use ";" Luke!!
and in general - to read what is &&

X
xotkot, 2019-02-12
@xotkot

tail -qn5 /path/to/file{1..3}.ext
if at all you need to ignore the error then:
tail -qn5 /path/to/file{1..3}.ext 2>/dev/null

V
Vladimir, 2019-02-12
@idskill

xargs you can try using

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question