Sunday, 25 August 2013

Only output most recent 10 (or n) lines of a lengthy command output [migrated]

Only output most recent 10 (or n) lines of a lengthy command output
[migrated]

I have currently worked alot with shell and bash on linux.
I have made tons of backups scripts and much more.
In many cases I have a command that outputs thousands of lines. I actually
need these lines in order to see the progress of the command. But I do not
need to see more than the 10 most recent lines.
How can I do that?
I already tried using a pipe and tail. But it did not work. I just got the
last ten lines after the original command finished:
whatever command that has too much output | tail -f
It is important that the console does not get cleared or something like
this because there is some important infomation that gets printed right
before the command with the lengthy output.
An example:
echo "Very important information. MUST BE VISIBLE!"
# This gives me about 10,000 lines of output pretty fast!
# This output should be shrinked down to the most recent 10
tar -cvf "Bckup.tar" "folder to backup/"
# More code
I hope this clears it up.

No comments:

Post a Comment