Hot answers tagged

100

Surround the command with quotes watch -n 1 'tail -n 200 log/site_dev.log | fgrep Doctrine'


86

Some implementations of tail have an option for this; here's the description from the man page for GNU tail: -F same as --follow=name --retry -f, --follow[={name|descriptor}] output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent --retry keep trying to open a file even when it is or becomes ...


64

You are probably looking for some combination of messages from various log files. Try: tail -f /var/log/{messages,kernel,dmesg,syslog} …to get a pretty good overview of the system. If you want more or less than that, research what log file the messages you want to see are being placed in. Also look into using multitail to file and color code and filter ...


54

Alternative is tail -F command. The -F option implies --follow=name with --retry option, so tail is watching your file even if it has been deleted and created again.


43

Just make it @#$%ing work You want to print output of dmesg, constantly, immediately Dmesg is printing the kernel ring buffer (see man dmesg) The kernel ring buffer is a special proc file, /proc/kmsg (see man proc) Read /proc/kmsg directly, ie cat /proc/kmsg. Now, if you read the friendly proc manual, it'll sternly warn you to let only one user (who must ...


31

You almost wrote the answer, which is : tail -f file.log | grep "foobar" That's it.


25

The accepted answer isn't working for me, plus it's confusing and it changes the log file. I'm using something like this: tail -f logfile.log | while read LOGLINE do [[ "${LOGLINE}" == *"Server Started"* ]] && pkill -P $$ tail done If the log line matches the pattern, kill the "tail" started by this script. Note: if you want to also view the ...


21

-f follows by inode. If you want to follow by name, such as when a program completely recreates the file, then use -F instead.


21

You can run less +F filename in order to view file in tail -f fashion. You can press Shift+F while viewing file in less to switch to forwarding mode, and Ctrl+C to leave this mode.


20

For those interested in linux, since kernel kernel 3.5.0: # dmesg -w Also on systems with systemd you can: # journalctl -kf


20

This works: while ! tail -f bar/somefile.log ; do sleep 1 ; done


19

Here's a variant on djeikyb's answer that's actually tested, and fixes a couple of bugs. watch 'sudo dmesg -c >> /tmp/dmesg.log; tail -n 40 /tmp/dmesg.log' The important trick is that we're doing dmesg -c, which clears the ring buffer after it prints -- thus, each time through we're only printing what's new since the last time. You'll need to be ...


17

Using Windows Powershell, you can use Get-Content < filename > -wait There's also a discussion of a Windows Server 2003 tools package that has a tail program which supports -f


16

There already is a nice tool for that: split > man 1 split NAME split -- split a file into pieces SYNOPSIS split [-l line_count] [-a suffix_length] [file [prefix]] split -b byte_count[K|k|M|m|G|g] [-a suffix_length] [file [prefix]] split -p pattern [-a suffix_length] [file [prefix]] split --bytes 50M test.out test.out_ would ...


15

You're not mentioning which OS you need it for, but tailon linux has the --retry and --follow options that will do just that; tail --retry --follow=name somefile.log


15

View > Clear Scrollback or press ⌘+K


15

Try watch. Taken from here: watch -d ls -l A friend and I tried this a moment ago, it seems that the highlighting doesn't really work correctly, it will highlight a seemingly random selection. I've tried this in an OS X Terminal ssh'd to a RHEL5 machine and my friend has tried in a Ubuntu GUI terminal. Unfortunately inotifywait is not present on the ...


14

If you have GNU head, you can use head -n -5 file.txt to print all but the last 5 lines of file.txt. If head -n takes no negative arguments, try head -n $(( $(wc -l file.txt | awk '{print $1}') - 5 )) file.txt


13

I might be wrong, but wouldn't this achieve the same thing more simply? tail -f -n 200 log/site_dev.log | grep Doctrine


9

There are a few ways to get tail to exit: Poor Approach: Force tail to write another line You can force tail to write another line of output immediately after grep has found a match and exited. This will cause tail to get a SIGPIPE, causing it to exit. One way to do this is to modify the file being monitored by tail after grep exits. Here is some ...


9

You should use sed. sed -n -e 45000000,45000100p -e 45000101q bigfile > savedlines This tells sed to print lines 45000000-45000100 inclusive, and to quit on line 45000101.


8

tail supports several files, for example: tail -q -f file1 file2


7

I have had good luck with http://sourceforge.net/projects/tailforwin32/. It has some nice options for fonts, colors and keyword highlighting. Feels lightweight and fast to me.


6

tail -f mylogfile & sleep 60; kill $!


6

From the tail man page: The tail utility displays the contents of file or, by default, its standard input, to the standard output. The display begins at a byte, line or 512-byte block location in the input. Numbers having a leading plus ("+") sign are relative to the beginning of the input, for example, "-c +2" starts the display at the second byte ...


6

Have a look at the -F option. I think it suits your purpose. From info tail: -F This option is the same as `--follow=name --retry'. That is, tail will attempt to reopen a file when it is removed. Should this fail, tail will keep trying until it becomes accessible again.


6

So after doing some testing, I found a quick 1-line way to make this work. It appears tail -f will quit when grep quits, but there's a catch. It appears to only be triggered if the file is opened and closed. I've accomplished this by appending the empty string to the file when grep finds the match. tail -f logfile |grep -m 1 "Server Started" | xargs echo ""...


6

If you're using Bash (at least, but it seems it's not defined by POSIX, so it may be missing in some shells), you can use the syntax grep -m 1 "Server Started" <(tail -f logfile.log) It works pretty much like the FIFO solutions already mentioned, but much simpler to write.


6

$ dd if=big_file.bin skip=1750 ibs=1MB count=10 of=big_file.bin.part You might want to spend some time reading and understanding dd.



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