Skip to main content
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 "...
Toufic's user avatar
  • 1,871
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 <== ...
mpowered's user avatar
  • 689
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 ...
dr_'s user avatar
  • 32.4k
56 votes
Accepted

'tail -f' for a specific amount of time

With GNU timeout: timeout 20 tail -f /path/to/file
cuonglm's user avatar
  • 158k
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 ...
Marcus Müller's user avatar
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=...
Stephen Kitt's user avatar
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 ...
Stéphane Chazelas's user avatar
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. ...
ilkkachu's user avatar
  • 148k
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/...
Michael Homer's user avatar
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 ...
Callie J's user avatar
  • 301
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 (...
Josh's user avatar
  • 8,778
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 | ...
Iskustvo's user avatar
  • 988
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 ...
Stéphane Chazelas's user avatar
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.
admstg's user avatar
  • 831
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 ...
Kusalananda's user avatar
  • 356k
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; # ...
Stéphane Chazelas's user avatar
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 ...
Stephen Kitt's user avatar
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 ...
Basile Starynkevitch's user avatar
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 ...
Stéphane Chazelas's user avatar
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 -...
Kusalananda's user avatar
  • 356k
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 ...
muru's user avatar
  • 77.9k
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 $...
DopeGhoti's user avatar
  • 79.2k
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 ...
ilkkachu's user avatar
  • 148k
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" ...
Stéphane Chazelas's user avatar
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 ...
Kusalananda's user avatar
  • 356k
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 ...
αғsнιη's user avatar
  • 41.9k
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 *...
MacMartin's user avatar
  • 3,164
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 ...
Stéphane Chazelas's user avatar
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, ...
Stephen Kitt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible