Watching updates at the end of a file, with or without the tail utility

learn more… | top users | synonyms

121
votes
15answers
55k views

How to have tail -f show colored output

I'd like to be able to tail the output of a server log file that has messages like: INFO SEVERE etc, and if it's SEVERE, show the line in red; if it's INFO, in green. What kind of alias can I ...
44
votes
6answers
66k views

cat line X to line Y on a huge file

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010). From what I understand I can do this by piping head into tail or viceversa, i.e. head -A ...
1
vote
1answer
39 views

What is the reverse of tail -c +K?

I was reading this thread. The command tail -c +K /tmp/1 outputs bytes starting with the Kth of each file. From man tail -c, --bytes=K output the last K bytes; alternatively, use -c ...
30
votes
8answers
13k views

How to obtain inverse behavior for `tail` and `head`?

Is there a way to head/tail a document and get the reverse output; because you don't know how many lines there are in a document? I.e. I just want to get everything but the first 2 lines of foo.txt ...
24
votes
2answers
5k views

The 'less' command-line equivalent of 'tail -f'

I would like to open up a file using less, and have it automatically scroll the file similar to tail -f. I know that I can do less file, and then hit Shift-F to forward forever; like tail -f. I need ...
5
votes
2answers
2k views

Negative arguments to head / tail

Variants of this question have certainly been asked several times in different places, but I am trying to remove the last M lines from a file without luck. The second most voted answer in this ...
2
votes
3answers
238 views

View only the new entries in a growing log file

tail -f x.log I use this command to see a growing log file in the command prompt. I am interested only in seeing the log lines that are written to the file after running tail -f and not interested ...
1
vote
1answer
54 views

Can someone explain this tail + line to me?

I'm looking through some of the scripts that are on the servers and came across an 80MB shell script. Naturally curious I decided to look in there and came across this line: tail +4802 $0 | zcat - | ...
5
votes
4answers
2k views

is there an alternative to tail -f that has convenient scrolling? [duplicate]

I'm usually inside GNU Screen or tmux, which doesn't give me excellent scrolling functionality. Is there an alternative to tail -f that allows me to quickly scroll up? A tool that is like most is to ...
21
votes
4answers
4k views

monitor files (ala tail -f) in an entire directory (even new ones)

I normally watch many logs in a directory doing tail -f directory/*. The problem is that a new log is created after that, it will not show in the screen (because * was expanded already). Is there a ...
0
votes
1answer
32 views

Clear terminal window before tail -f output

I have the following script running every 3 minutes with cron: #!/bin/bash cd ~/Documents/Fetch/ wget remotehost/data.txt --output-document=tmp cp tmp data.txt rm tmp To fetch a self-generated php ...
7
votes
3answers
2k views

How to tail multiple files using tail -0f in Linux/AIX

I tried tailing two files using the option: tail -0f file1.log -0f file2.log In Linux I see an error "tail : can process only one file at a time". In AIX I see the error as "Invalid options". ...
6
votes
3answers
2k views

Suppress 'file truncated' messages when using tail

I'm tailing a log file using tail -f messages.log and this is part of the output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget tellus sit amet odio porttitor rhoncus. Donec ...
3
votes
2answers
86 views

Check if conditional with awk for matches in logfile

I want to check the auth.log file for accepted sshd connections and execute an action if any are found. Here is my code: tail -f /var/log/auth.log | awk '{ if($0 ~ /sshd/ && $0 ~ /Accepted/) ...
19
votes
9answers
30k views

Command to display first few and last few lines of a file

I have a file with many rows, and each row has a timestamp at the starting, like [Thread-3] (21/09/12 06:17:38:672) logged message from code..... So, I frequently check 2 things from this log file. ...
1
vote
1answer
45 views

tail -f error_log | cowsay

I'm watching the error logs on my local setup. I'd like to have the errors print out in cowsay, you know, for fun. tail -f error_log | cowsay doesn't work. Any ideas?
4
votes
5answers
592 views

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

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 ...
4
votes
3answers
181 views

Redirect the tail output to a file then stop when match found

there is this log file that data coming in is continuous. what i wanted to happen is to tail -f this log file then redirect it to a file with the ff conditions example of the log files content ...
4
votes
1answer
171 views

Does less have a feature like tail --follow=name (-F)

The command less can be used to replace tail in tail -f file to provide features like handling binary output and navigating the scrollback: less +F file The + prefix means "pretend I type that ...
4
votes
4answers
261 views

Make tail not modify the charset of the terminal

In a linux terminal (CentOS) I am using the command tail --follow=name my-rolling-file.log in order to see the logs of my application. Sometimes in the log there is some binary data dumped (I dump ...
2
votes
4answers
171 views

Show filename at begining of each line when tailing multiple files at once?

when tailing multiple files at once as shown below, is any there any way to show the file name at the start of each line? tail -f one.log two.log current output ==> one.log <== contents of ...
1
vote
1answer
41 views

“tail -f” in GNOME Terminal - scrolling to previous lines breaks if there's been lots of subsequent output

I'm viewing a log file with "tail -f" using GNOME Terminal. The log has a lot of input constantly coming into it, and what I find happens is that I scroll up to a previous section, and I'm reading ...
1
vote
4answers
2k views

Tail -f the most recent log file

In a few spots I got this to work ls -rt /path/to/log/file/ | tail -1 | xargs tail -f But I can't figure out why it won't always work (This is quick fix until I get the log rolling fixed here)
6
votes
1answer
157 views

Is `tail -f` more efficient than `less +F`?

This article pointed out some reasons to use less +F over tail -f. Most of the reasons are about the features, not technical reasons: less +F can highlight, search, navigate through file. How about ...
3
votes
2answers
231 views

tail display whole file and then only changes [duplicate]

My Linux version is 2.6.32-47-server (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1) ) #109-Ubuntu SMP Tue May 7 02:17:05 UTC 2013 I am currently doing a tail -f file and life is good. But that only ...
2
votes
2answers
84 views

Print file contents and delete the printed content* from the file

In Linux, from a bash shell, how can I print the contents of a file and remove the content I just printed content from the file? I have a program writing texts to a file repeatedly. On a Linux shell ...
2
votes
4answers
667 views

How to tail a file over the network?

How can I tail -f a file that over the network, say at \\192.168.2.130\public\print.log? I have tried the variations of the following: tail -f //192.168.2.130/Southpaw/Tactic/print.log which erred ...
2
votes
1answer
37 views

Is it possible to tail -f output to a single line?

less has an option -S or --chop-lines which prevents lines from wrapping and shows output as one line (often extended beyond screen). Is it possible to do this with tail -f? The tail man page ...
2
votes
3answers
184 views

Keep a tally from a log file

I have a file called output.log which has this content: Thread started Thread finished Thread started Thread finished Thread started Thread started I monitor its output using: tail -f output.log ...
3
votes
2answers
158 views

Repeatedly execute bash command while there's no output from another process

I'm running fs_usage to detect access to an object on my filesystem. sudo fs_usage -w | grep -E 'object' I now want to run a touch command on that object every 5 seconds as long as there's no new ...
0
votes
2answers
84 views

Will “tail -100 | sed -n 1p” only read one line?

I'm searching backwards from the end of a file, it's probably easiest to explain by showing my code: enough=0 numberOfLines=100 fileName="/path/to.file" # Tail the last $numberOfLines lines; if the ...
4
votes
1answer
112 views

tail -f produces no output in Ubuntu live CD

For some test I start Ubuntu Live from USB. I'm trying to use tail command to show debug log, but it doesn't work. I also test opening two terminals (t1, t2) with this code: t1: touch a t2: ...
0
votes
0answers
26 views

how can I redirect the grepped output of tail -f to a file? [duplicate]

I want to do this: tail -f /var/log/apache2/access.log | grep 'POST \/review' But I want the output to go to a file and I want this to run constantly for a day or two. I tried a simple script ...
0
votes
1answer
52 views

tail-ing a filename that is a date [duplicate]

I am creating a logfile from kermit named the current date (which is in the format of DD MMM YYYY - which can not be changed AFAIK), and using the file name as today's date. I then have a Bash script ...
11
votes
4answers
3k views

Follow a pipe using less?

Can less follow (by pressing F) a piped input (similarly to a file)? For a file that is being written to, the command less <file> will follow the file when pressing F. But if I have a ...
14
votes
4answers
2k views

How to do a continous 'wc -l' with gnu texttools?

I know of course that cat logfile.txt | wc -l 120 will tell me the number of lines in a file. Whereas tail -f logfile.txt will show me the new lines that another program writes to logfile.txt. ...
4
votes
5answers
340 views

Using head and tail to grab different sets of lines and saving into same file

So this is for homework, but I will not be asking the specific homework question. I need to use head and tail to grab different sets of line from one file. So like lines 6-11 and lines 19-24 and ...
0
votes
1answer
50 views

Use tail and grep to send an IRC message?

How do I use a command like: tail -f /home/user/log.txt | grep '!calladmin\|admin' To send an IRC message to me when !calladmin or admin are posted in the log? Or is there an easier way to do ...
-1
votes
1answer
55 views

Hash different, is it safe?

The first time I downloaded Tails image which is with different sha256sum than the webpage giving, so I downloaded it once again and this time it is correct. Then I unpakeged all the files inside the ...
0
votes
1answer
109 views

Pipe stdout to command on stdout

If I had a running process like tail -F watch.txt and I wanted to capture the stdout from this running process and pipe it to another command on stdout how could this be done? Here's an example of a ...
3
votes
2answers
223 views

Coloring tail output with perl

tail -f logfile.log | perl -pe 's/.*foo*/\e[1;41m$&\e[0m/g' will color all the lines containing the pattern "foo" in the logfile.log file. How can I make use of this in order to highlight ...
0
votes
0answers
58 views

Why does GNU head/tail read the whole file? [duplicate]

I have a huge file and want to see its beginning and end. However, when I use head and tail, it apparently tries to read the whole file. Since the file is larger than a terabyte, this takes a very ...
2
votes
2answers
32 views

Getting transient PID from log into a PS search before it dies

I have a transient prelink process populating our audit log, but we're not sure what the process is. The error log gives us the PID, but it disappears pretty much instantly, as the process finishes ...
2
votes
1answer
628 views

splitting a CSV and keeping the header without intermediate files [closed]

I am trying to split a dozen 100MB+ csv files into managable smaller files for a curl post. I have managed to do it but with a lot of temporary files and IO. It's taking an eternity. I am hoping ...
3
votes
1answer
621 views

grep not working in a for loop over a list

I have some log files. And I have a list of user ids. My log files are in a particular format log-yyyy-mm-dd e.g. log-2014-09-30 I am trying to search each userId in the log file. This is what I am ...
40
votes
1answer
7k views

How to do a `tail -f` of log rotated files?

On a long running system I usually have a terminal with $ tail -f /var/log/kern.log or something like this open. But from time to time I have to restart such command because no new messages are ...
4
votes
3answers
247 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...
6
votes
1answer
2k views

Tail log file on multiple machines over ssh

I'm trying to tail a log file on multiple remote machines and forward the output to my local workstation. I want connections to close when pressing Ctrl-C. At the moment I have the following function ...
2
votes
2answers
309 views

cygwin, tail -F and rapidly filling/rotatinglogs

I'm using cygwin tail to follow busy java web application logs, on a windows server, generating roughly 16Gb worth of logs a day. I"m constrained to 10MB log sizes, so the files roll very often. ...
27
votes
4answers
2k views

Why does “tail -f … | tail” fail to produce any output?

Why does the following command not produce any output? $ tail -f /etc/passwd | tail After reading about buffering, I tried the following to no avail: $ tail -f /etc/passwd | stdbuf -oL tail Note ...