Questions tagged [tail]
Watching updates at the end of a file, with or without the tail utility
432 questions
0
votes
0
answers
38
views
Is there anything like `tail -f` but that can follow multiple files and show which file each line came from? [duplicate]
I'm trying to monitor multiple log files simultaneously, but when I use:
tail -f /var/log/app1.log /var/log/app2.log
I get mixed output and can't easily tell which file each line originated from. What ...
0
votes
2
answers
91
views
Never exit "less +F" if the tailed file disappears?
Under ubunu 22.04, I'm using the standard less pager.
When running less +F against a log file, I never want less +F to automatically exit if the log file disappears. Instead, I want the current view ...
8
votes
1
answer
976
views
What is the `-0` flag in `tail`? [duplicate]
The Logstash documentation said about the input file plugin that it
Stream events from files, normally by tailing them in a manner similar to tail -0F but optionally reading them from the beginning.
...
14
votes
1
answer
748
views
Why does `tail -c 4097 /dev/zero` exit immediately instead of blocking?
I observe that, on Ubuntu 24.04.2 with coreutils version 9.4-3ubuntu6, running:
$ tail -c 4097 /dev/zero
$ echo $?
0
exits immediately with a status code of 0. I expected the command to block ...
0
votes
1
answer
118
views
Does "less" have "--retry" option like "tail"?
I'm using less to continuously trace Squid log file (as well as UFW log) with this command:
less --follow-name -K +F /var/log/squid/access.log
And at the time of rotation of Squid log less quits. I ...
14
votes
1
answer
679
views
"Tail -f" on symlink that points to a file on another drive has interval stops, but not when tailing the original file
I'm encountering a strange behaviour with tail -f, when tailing a symlink on an Ubuntu machine.
Apparently, tail uses the default update interval of 1 second. If tailing the original file, it seems to ...
0
votes
1
answer
56
views
Run a few identical process and then kill one of them
Problem:
Need to run several process, especially it will be “tail -f log.log >> wrile_log.log” proces to collect log.
Commands can be run at the different time for same log file. This is not ...
1
vote
1
answer
253
views
How to know when a following tail moves from old file to the new one
So, I am working with tail -F ( or tail --follow=filename). Now it works as advertised and when a rollover occurs it will move to the new file.
This is great and helps me keep track of my logs. The ...
1
vote
3
answers
367
views
How to tail continuously a log file that is being deleted and recreated?
I need to extract information from a log file that is deleted and recreated every time a program runs. After detecting that the file exists (again), I would like to tail it for a certain regexp.
The ...
0
votes
0
answers
639
views
How can I save the output of tail to my clipboard or somewhere on a SSH session where there is only a unidirectional connection and server is limited?
I have to report some logs from some of the servers in our infrastructure which I have limited permissions on. Every time I copy 1000 lines of logs and paste it into Slack, I can't do scp from the ...
16
votes
5
answers
13k
views
How do I read the last lines of a huge log file?
I have a log of 55GB in size.
I tried:
cat logfile.log | tail
But this approach takes a lot of time. Is there any way to read huge files faster or any other approach?
0
votes
0
answers
324
views
Can't clear / scroll-back buffer when using tail -f alacritty?
When I use tail with the -f option, I can not find anyway to clear the screen. It just shows a ^L. Same problem when following live logs with docker.
While I'm just in the shell, the cmd-k works fine.
...
1
vote
0
answers
37
views
pfSense (FreeBSD) - tail -f not showing entire log when filtering with cut or sed [duplicate]
I have a strange problem when trying to display logs on pfSense (and I can reproduce the same problem on Ubuntu server also).
The problem is this (with examples):
I'm trying to display a running dhcp ...
1
vote
1
answer
703
views
How to tail -f multiple files and grep each file individually in single output?
I have several log files (related to my webserver aka various error_log, access_log, etc.) that I want to monitor in real time, ie to see recent updates AND I need to filter each file individually ...
-1
votes
2
answers
92
views
Linux "watch" command showing last 30 lines of nft list ruleset [duplicate]
I want to constantly see last 30 lines of code "nfc list ruleset" in Debian Bash. Something like this:
watch -n 1 nft list ruleset | tail -n 30
But above code doesn't show last 30 lines of &...
0
votes
1
answer
78
views
tail -f, multi sed [duplicate]
I can do
tail -vf -c5 thefile \
| cat -n \
| sed -E 's/a/b/g' \
;
But the following gives no output.
tail -vf -c5 thefile \
| cat -n \
| sed -E '...
3
votes
2
answers
555
views
Tail -f | sed. Modify text for color
I am modifying the text following tail -f.
I have the following program that monitors a file:
tail -vf -c5 /tmp/index \
| cat -n \
| ...
1
vote
1
answer
1k
views
Alpine linux: replace BusyBox tail to GNU tail
I need to use the tail ... --pid=PID option in my docker container that is based on Alpine image in order to I can kill the running background tail process automatically.
Unfortunately the BusyBox ...
1
vote
1
answer
86
views
How to follow constantly a keyword in multiple files and include filename beginning of each reported line
tail -f a/b/c.log d/e/f.log
logs like this:
==> a/b/c.log <==
xxx
yyy
Exception happened 1
zzz
==> d/e/f.log <==
rrr
Exception happened 2
sss
How to change command so that the lines ...
0
votes
2
answers
785
views
Extract parts of a string using head and tail only
Hello I would like to know if there is a way where I can only use head, tail, and pipes (and redirection eventually) to extract and output the start, middle characters, and end of a string
Example:
...
1
vote
2
answers
3k
views
Head/Tail command to grab multiple sets of lines
I have to grab the first two lines, the lines 43 and 44, and the last 2 lines from a file in one conduct of commands.
Is there away to print those while only using head, tail and pipe commands AND ...
0
votes
4
answers
433
views
How to view a log file that's worth 10GB+?
The ways that I've thought of:
If you get to reproduce the scenario in real time. Use
tail -f application.log | tee /tmp/tailed_log
But it's not sure that we'll get to reproduce the scenario in real ...
0
votes
2
answers
322
views
Side by side output from two `tail -f` commands
I have two scripts emitting single string to log files periodically that I need to tail -f and combine side by side for which I am using paste. This works but I am unable to pipe the output to another ...
3
votes
1
answer
169
views
Save the output of earlier tailed logs to a file?
Is it possible to save the output of earlier tailed logs to a file?
Steps to Reproduce this issue:
tail -f application.log
Ctrl+C to end the logs
Save that output to a file now.
I am assuming an ...
0
votes
1
answer
918
views
Continuously display last line of command output without clearing the screen
I want to print only the last line of the output of a command on the same line continuously without clearing the screen. This would be part of another function. Let's say my script has the following ...
1
vote
1
answer
1k
views
How to stop "tail -f" in a script and exit if a certain condition is fulfilled?
I'm trying to come up with a script for managing jobs on a supercomputer. The details don't matter much, but a key point is that the script starts to tail -f a file once it appears. Now this would run ...
0
votes
1
answer
207
views
Sleep vs tail to wait on process
Currently I do:
while [ -d "/proc/$PID" ]; do
sleep 1
done
To wait for a process to exit. If I would replace it with:
tail --pid=$PID -f /dev/null
Would that be more efficient for the ...
1
vote
1
answer
182
views
How to make tail command end itself
In my app I use tail -q -f -n +1 [file name] to read current data of a file (dynamically growing file) and continue reading new chunks until the end. But that command never exits. It stays alive in ...
2
votes
6
answers
272
views
Only pipe output if at least n lines
I often want to grep output from processes that include a few header lines. But if grep would remove all actual content lines, I don't want to display the header lines. For this to work I would need a ...
1
vote
0
answers
92
views
Random timeout on basic operation in bash
Context
I have a GitHub Action running on a linux machine.
It does the following (might want to skip to problem first as most of this might be irrelevant):
pwd: /home/runner/work/net.twisterrob....
2
votes
4
answers
2k
views
Grep and find to get the last match in multiple files [duplicate]
Assume two files with the following content:
$ cat ttest1.txt
x = 1
x = 3
y = 5
$ cat ttest2.txt
x = 4
x = 10
y = 3
I would like to recursively grep the files for x and print the last instance in ...
0
votes
1
answer
63
views
maintain appended logs in separate file despite tail command termination
I have tomcat catalina.log file that keeps getting updated.
I wish to maintain its past 500 lines + any appended logs into a new file catalina.log_new for the next 2 hours.
To start off I run nohup ...
0
votes
1
answer
354
views
How to exit a FOR loop on detecton of "error" stream using TAIL
I have a "for" loop which passes the results to a file called "results"
Occasionally an error stream is detected and the loop continues trying within the loop for a number of times ...
0
votes
1
answer
350
views
How to NOT append nohup output to a file but replace it?
Lately I needed to be able to run a script in the background and monitor its output from another machine. For this reason I was able to use this command:
$ nohup ./rsync.sh > ./output.txt
This is ...
12
votes
2
answers
2k
views
Why can't I do two greps after a tail?
I'm able to run this command successfully:
tail -f my_file.txt | grep foo
It shows only the lines with the string foo, and it keeps showing them.
But when I run this command:
tail -f my_file.txt | ...
2
votes
1
answer
136
views
Flush output of `tail -f` into a file?
I have an app which dumps a lot of log messages. I want to catch a middle of that log, which happens as a reaction to an event.
Tried this:
tmpfile=`mktemp`
tail -n1 -f appA_log_file.txt >> $...
1
vote
1
answer
189
views
"tail -f", but on a file which gets rewritten (downloaded) again and again without outputting then content over and over again?
I've got log files which get downloaded via cron job. If a file is updated on the remote location, the local copy gets rewritten from the beginning even if only data has been appended.
Tools like tail ...
2
votes
1
answer
770
views
tail -1000f doesn't show the same output as tail -1000
I am trying to execute
tail -100000f MXMLExchangeMonitoring_Mx3.log | egrep "INTENTO.*Workflow" | cut -d ":" -f "3" | cut -c 3,4,5,6 | awk '{if($1>20)print$1}'
and I'...
0
votes
1
answer
127
views
How to follow logs while avoiding line wrapping w/ horizontal scroll enabled?
In the terminal, if I don't want to have logs of a program wrap, I can pipe those to less -S.
However, horizontal scroll with keyboard doesn't work unless I Ctrl+C, and after that, I don't know how to ...
0
votes
0
answers
193
views
Watch file for specific text and exit
I'm trying to write a command that exits cleanly when a specific string is eventually written to a log file.
I've tried the following but it never exits.
Setup: create a file for the purposes of ...
1
vote
0
answers
25
views
Weird grep behavior with invalid UTF8 input [duplicate]
I need to monitor a log file which sometimes contains invalid UTF8 characters.
Like this:
shaozr@fedora utf8-cut (bear_from_3.1.18) $ tail -F a.txt
a我々はMozartが好きです。
a我々はBachも好きです。
a▒▒▒々はMozartが好きです。
a▒...
1
vote
1
answer
1k
views
How is the default stdout buffering set?
Running on Red Hat EL7, we have these great long lines in our log files so I do a
tail -f Log | cut -c1-$COLUMNS
This works great on some systems but other--apparently identical--systems, the pipe ...
3
votes
3
answers
313
views
How to get around issue with `tail -f` not emitting EOF and make it works with tools like `csvtool`?
I basically want to do this:
tail -f trades.csv | csvtool readable -
I want to read a CSV file in a readable format using csvtool and I want to keep watching it.
I think that command doesn't work ...
2
votes
3
answers
2k
views
Shell script to filter string from a data stream and output to screen
I am trying to make it easy to tail a log file and print to the screen only the output of a single field.
I have the log file that looks like this on a Linux machine:
2022-10-21 16:00:08;areq_in=0;...
1
vote
0
answers
20
views
What's wrong with my log file generation?
I'd like to capture and filter the logs from my ESP32 peripheral from the serial port and generate a new log file with the selected line.
I do as follows:
$ (((stty speed 115200 && cat) </...
0
votes
2
answers
125
views
Select a microservice with awk and create a file with the current date and version
I would like to see the logs for a microservice with the latest version and send its content to a file according to the date.
user@MacBook-Pro ~ % kubectl -n bci-api get pods | grep ms-example-...
1
vote
2
answers
65
views
How to terminate _follow_ mode in **less** (`+F`) from pipe?
Assuming the following dummy command in bash:
### dummy long_operation_cmd function, for easy reproduction:
function long_operation_cmd() {
echo "operation 1"
sleep 5
echo "...
1
vote
1
answer
200
views
bash looping over files while tailing logs
I'm running a daemon that process files in a specific dir.
I want to process those one by one. so idea is I will copy files 1 by 1 in daemon dir, and tail its log, 2nd file should be copied to daemon ...
1
vote
3
answers
1k
views
How to suffix or prefix each line coming from tail command
I have a file and I am running a tail command on this file like this
tail -n+1 -F "./log/catalina.log"
I want to suffix or prefix another string to each line coming out of this file, which ...
0
votes
0
answers
246
views
SCP results look strange when using >> to append to file
I am trying to record a reoccurring test to a txt file using tail but there is an issue with the output.
The commands I am running are:
script -q /dev/stdout -c 'scp /home/user/test.img user@pc28:/tmp'...