177
votes
Combining tail && journalctl
You could use:
journalctl -u service-name -f
-f, --follow
Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.
Here I've added "...
58
votes
How to tail multiple files using tail -0f in Linux/AIX
In OSX and Linux, using
tail -f <file1> <file2>
works great for me. Another nice thing is that it has the following output:
==> /srv/www/my-app/shared/log/nginx.access.log <==
...
57
votes
Accepted
How to quit `tail -f` mode without using `Ctrl+c`?
As said in the comments, Ctrl-C does not kill the tail process, which is done by sending either a SIGTERM or SIGKILL signal (the infamous -9...); it merely sends a SIGINT which tells tail to end the ...
56
votes
Accepted
54
votes
Accepted
How do I read the last lines of a huge log file?
cat logifle.log | … here is superfluous, and actually contributes to it being slow. tail logfile.log without the cat would make a lot more sense!
It's going to be much faster, because when the input ...
42
votes
Accepted
tail -f, but when the file is deleted and re-created (not appended)
If your tail supports it, use tail -F, it works nicely with disappearing and re-appearing files. Just make sure you start tail from a directory which will stay in place.
-F is short-hand for --follow=...
36
votes
Accepted
Why does piping `mysql` to 'tail' change the output format?
It's not tail, it's the piping.
mysql uses a tabular with ASCII boxing output format when its stdout is a terminal device, when it's intended for a user, and reverts to a scripting format when it's ...
27
votes
Accepted
Why can't I do two greps after a tail?
That's because the default behaviour of the C runtime library is to buffer writes to stdout until a full block of data is written (some kilobytes, usually), unless stdout is connected to a terminal.
...
22
votes
Accepted
Echoing a tail command produces unexpected output?
Your crontab line has one or more asterisks * in it, indicating "any time". When that line is substituted in from the command substitution, the result is something like
echo * * * * * cmd > /path/...
20
votes
'tail -f' for a specific amount of time
For completeness sake, without timeout, you can do this:
#!/bin/sh
tail -f /var/log/syslog &
me=$!
trap "kill $me" INT TERM HUP QUIT EXIT
sleep 20
The trap line ensures that when the script or ...
19
votes
How to quit `tail -f` mode without using `Ctrl+c`?
What I want is a normal way to quit, like q in top.
That's ControlC :)
I am just curious about the question, because I feel that killing the process is not a good way to quit something.
^C (...
19
votes
Display only the penultimate (second last) row of a text
There are many ways to do that, but this is the fastest one I've found -- and is the cleanest in my opinion.
Assuming that the poem is written in a file named poem, you can use:
tail -n 2 poem | ...
19
votes
"Tail -f" on symlink that points to a file on another drive has interval stops, but not when tailing the original file
On Linux-based systems, GNU tail uses the inotify feature to detect when there are changes to files. That way it doesn't need to poll every second (or whatever you specify for -s).
It is a bit brittle ...
17
votes
How do I read the last lines of a huge log file?
You should use directly tail logfile to get the last ten lines of the file without reading all the file as cat logfile | tail is doing.
16
votes
Accepted
What is the `-0` flag in `tail`?
Using tail -0 is the same as using tail -n 0, that is, "show the zero last lines of the input data". In general, -N, for some integer N, is the same as -n N (this was allowed by older ...
14
votes
Accepted
tail -f, insert line break after log is idle for 3 seconds?
You could always implement the tail -f (well here, unless you uncomment the seek(), more like tail -n +1 -f as we're dumping the whole file) by hand with perl for instance:
perl -e '
$| = 1;
# ...
13
votes
Accepted
"tail -s N" does not sleep for N seconds before updating
The full manual describes -s as
Change the number of seconds to wait between iterations (the default is 1.0). During one iteration, every specified file is checked to see if it has changed size. When ...
12
votes
How to quit `tail -f` mode without using `Ctrl+c`?
tail -f filename, how to quit the mode without use Ctrl c to kill the process
You can't do that. Perhaps you wanted to run tail -f somefile | less
The Ctrl c is interpreted by the tty subsystem (and ...
12
votes
Accepted
Reading a named pipe: tail or cat?
When you do:
cat fifo
Assuming no other process has opened the fifo for writing yet, cat will block on the open() system call. When another process opens the file for writing, a pipe will be ...
12
votes
Is it possible to change tail's default line count?
No, the default number of lines produced by tail (and head) is mandated by the POSIX standard:
If neither -c nor -n is specified, -n 10 shall be assumed.
To get a different number of lines, use the -...
12
votes
What logic does the command "exec tail -n +3 $0" from grub2 config have?
If you're talking about /etc/grub.d/40_custom:
$ cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries ...
12
votes
Accepted
Read logs from one process during run of some command
This is made rather straightforward by sending your background processes to, well, the background:
foo.sh &
mypid=$!
tail -f /path/to/logs.log > /path/to/partial.log &
tailpid=$!
wait $...
11
votes
Accepted
What logic does the command "exec tail -n +3 $0" from grub2 config have?
tail -n +3 prints its input, starting at line 3 (man page). $0 is the name of the script in a shell script (Bash special parameters) and exec (Bash builtins) replaces the script with the command. You ...
11
votes
Accepted
How to cat named pipe without waiting
To prevent cat from hanging in the absence of any writer (in which case it's the opening of the fifo, not reading from it, that hangs), you can do:
cat 0<> "$my_named_pipe" <"$my_named_pipe"
...
11
votes
Move specific line from a position to another
Using ed (the line-editor that sed and grep are derived from):
printf '%s\n' '11m0' 'w bonjour2' 'q' | ed -s bonjour
This applies the editing command 11m0 to the file which moves line 11 to before ...
11
votes
Accepted
Pipe skip 99 lines out of every 100
Print 1st line and skip next N-1 lines out of every N lines.
awk -v N=100 'NR%N==1' infile
test with:
$ seq 1000 |awk -v N=100 'NR%N==1'
1
101
201
301
401
....
to pass the number of lines you want ...
10
votes
How do I make Vim behave like "tail -f"?
I like it short and without a lot of hacking.
You can run this oneliner from ex (whithin vim) when needed (or put each command in vimrc, for when log-files are opened.)
:set autoread | au CursorHold *...
10
votes
make tail -f exit on a broken pipe
It's the same things as in:
How to exit early on pipe close?
Grep slow to exit after finding match?
limit find output AND avoid signal 13
In:
cmd1 | cmd2
Your shell happens to wait until cmd1 ...
10
votes
Accepted
Why does `tail -c 4097 /dev/zero` exit immediately instead of blocking?
The first things to note is that device files are allowed to not support seek; perhaps surprisingly, seeking on such files succeeds without moving the position in the file.
Before version 9.6, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
tail × 432logs × 64
grep × 63
bash × 55
head × 48
pipe × 46
linux × 39
shell-script × 38
sed × 33
awk × 32
command-line × 32
text-processing × 28
shell × 24
files × 23
cat × 21
less × 21
monitoring × 15
terminal × 12
cut × 9
scripting × 8
io-redirection × 8
output × 8
ls × 7
colors × 7
stdout × 7