r/linux • u/[deleted] • Mar 30 '15
Stop using tail -f (mostly)
http://www.brianstorti.com/stop-using-tail/219
u/iaing Mar 30 '15
The single reason I use tail -F instead of less +F is that I can hit return a few times to leave a visually obvious blank space as a place marker.
86
u/whogots Mar 30 '15
I always feel like such a caveman when I do that, but it's so damned useful.
Occasionally I also make annotations in the fake white space, then copy that into Jira/wiki/whatever.
24
u/the_s_d Mar 30 '15
Agreed. Between that and the fact that I have essentially infinite scroll-back buffers on countless terminals means that I have little incentive to change to less, though I certainly use it plenty for other stuff.
7
u/basilarchia Mar 30 '15
feel like such a caveman
You are a smart caveman nonetheless. Lot's of us have done this and built very big successful things on the way. If I saw someone do this, I'd hire them on the spot.
0
Mar 30 '15
[deleted]
14
Mar 30 '15
Well, I feel like a caveman when I'm flailing around on a Solaris 10 sunfire box.
Yea, we still have some of those. Somehow.
4
Mar 30 '15
We have some Solaris boxes at work and I keep hitting up to go to the last command. It's upsetting.
4
u/tidux Mar 30 '15
set -o viESC-k
7
Mar 31 '15
oh oh oh! You made me look it up and I found that I can also just type
bashat the prompt and I can use bash shell rather than sh! History Ho!2
u/eythian Mar 31 '15
chsh?
1
Mar 31 '15
csh apparently - I'm still a little new to shells and their differences, so I didn't even think of just swapping to bash
3
1
Mar 31 '15
Give it a try! Add a user with useradd and then change their shell to bash. Do that once without changing their shell to bash, have them say "what is wrong with my command line it doesn't have tab completion" and you will never forget that command. Good times.
2
6
Mar 30 '15
I'm pretty sure that all three of those things can run Linux.
5
u/tidux Mar 31 '15
GNOME outreach for women
sparc64 Linux on a Sun Fire
installing Linux on a dead badger
It checks out.
3
u/andrewcooke Mar 30 '15
and i just did that a moment ago, so i'd know how much this job had advanced while i was killing time on reddit...
4
1
1
350
u/drrlvn Mar 30 '15
The problem is that less +F polls every second while tail -f uses inotify, which is both more efficient and responds faster to change.
6
u/WatchDogx Mar 30 '15
The distros I have seen of tail, specify a polling time, which would seem to contradict that.
75
u/dagbrown Mar 30 '15
When inotify is available,
tail -fuses that. When it's not available, it just polls.14
u/drrlvn Mar 30 '15
You can also use
tailffrom util-linux package which always uses inotify and is useful when yourtailis too old.6
Mar 30 '15
Which distros would those be?
16
u/t90fan Mar 30 '15
The tail in coreutils under ubuntu currently supports using inotify, for example. It falls back to to polling if the maximum number of inotify watches is exceeded and prints a warning.
1
Mar 30 '15
I think the use case is going to determine the appropriate binary to use, e.g. if you're looking at a rotating log vs a large log (say from an application).
1
Mar 30 '15
also it makes it easier to then do
tail -f file |grep sth. And thenC-ato get to start of line and replace it with cat to find all0
Mar 30 '15
[deleted]
37
u/sccrstud92 Mar 30 '15
I don't think it's a clickbait title. It could be a bad article, but the title and content agree at least.
56
u/paholg Mar 30 '15
Yes, but the title doesn't tell you much about the article. It's phrased so that you go "Why should I stop using tail -f? I better click and find out." That is what it means to be clickbait.
If the title were something like "Use less +F instead of tail -f" then it would convey much more what the article is about, but would filter out anyone who already knows about "less +F".
13
u/Talman Mar 31 '15
This is the definition of clickbait. The only wait it could have been been worse was "tail developers hate him!"
10
u/FatBruceWillis Mar 30 '15
MVP right here. I was going to click through to the article. You saved me.
-4
Mar 30 '15
The point of a title is to be a short phrase that lets the reader know what additional information they will learn if they read the entire article.
11
u/paholg Mar 30 '15
And this title doesn't do that. The article is about using "less +F" but it is mentioned nowhere in the title.
1
Mar 30 '15
When I read the title, is was pretty obvious to me that the content of the article would contain information about why I shouldn't use
tail -fand what I should use instead. As such, it functioned precisely how titles are supposed to function.5
u/paholg Mar 30 '15
When I read it, I thought it would point out some problem with
tail -f, some reason not to use it. It didn't. It just offered an alternative.2
Mar 30 '15
It certainly pointed out a problem with
tail -f:We all have been there: You are watching a file with tail -f, and then you need to search for something in this file, or just navigate up and down. Now you need to exit tail (or open a new shell), and ack this file or open it with vim to find what you are looking for. After that, you run tail again to continue watching the file. There's no need to do that when you are using less.
9
Mar 30 '15
A problem that hardly anyone has because of scroll buffers in modern terminal applications and terminal multiplexers.
The title is purposely vague to get you to click on it, it is click bait. A more terse title would have been "Why less +F is better than tail -f", but this would get less clicks because most people don't give a shit about that.
Simply saying "Stop using tail -f" will catch your attention because it could mean tail has a security exploit or some other more serious issue other than 'it has no built in scroll buffer'.
This is the definition of clickbait. Getting people to click an article that they wouldn't have clicked on if they knew what the article was actually about.
→ More replies (0)4
1
22
Mar 30 '15 edited Mar 30 '15
[removed] — view removed comment
14
Mar 30 '15
Did you ever found a case when that additional load was actually meaningful ?
2
Mar 30 '15
[removed] — view removed comment
6
Mar 30 '15
No, I meant load from polling
1
u/phessler Mar 31 '15
you ever try to read log files from a slow disk? or one that is in the process of dying? poll is hugely painful there.
1
1
u/holgerschurig Mar 31 '15
Maybe this comes over as arrogant. But for me, if a programmer still needs to poll today, it's either a bad programmer ... or a bad OS design. I look at you, Windows CE !
Also, not needing to poll is about latency, not load.
1
Mar 31 '15
inotify is great. but it isnt like not having it would hurt tail in most cases.
And it generally doesnt work over many network filesystems so you do have to have polling implementation in codebase anyway
1
u/GLneo Mar 30 '15
It's the principle of the design, use it everywhere and it would pile up.
1
Mar 31 '15
but you dont in tail. that feature is nice, but nowhere near necesary one. Only real use case is 'i tailed 5k files at once'. Now if it could do 'tail' on metadata (which files/dirs were created/ modified) this could be useful, but there are other tools for that.
Also one could argue that polling inode already cached in RAM might use less CPU than getting a ton of events from busy file
3
u/freedelete Mar 30 '15
inotify is ugly. It's not really surprising.
2
1
-19
u/ctx77 Mar 30 '15
Oh wow, FreeBSD is so advanced.. some tool used something more sophisticated than the Linux counterpart..
Lets all switch to FreeBSD immediately. Because it is so much more advanced.
1
Mar 31 '15
The only reason I don't run FreeBSD on my servers is because I don't want to deal with colocating hardware.
Thankfully, SmartOS offers a lot of the features I want from FreeBSD (Jails and ZFS, among other things).
168
u/swordgeek Mar 30 '15
There's a big difference between "here's a cool feature you might not know," and "you're doing it WRONG!!!"
The author would do well to learn that.
11
u/merreborn Mar 30 '15
This industry has a history of using inflamatory titles dating back nearly half a century. The classic "Goto considered harmful" would probably be labeled "clickbait" in today's climate... even though the paper predates the web by nearly 30 years.
Which of course leads us to “Considered Harmful” Essays Considered Harmful
1
42
u/whiprush Mar 30 '15
tail -F handles log rotation as well, which is handy.
3
u/basilarchia Mar 30 '15
I haven't switched to systemd yet, but does all this not work anymore because systemd does some crazy fucking logging shit? If so, I'm going to hate it. If not, ok, I just heard rumors in the wind that were mis-informed. (kinda like I am right now)
7
Mar 30 '15
It is called journald
Almost every distro does journald -> syslog passthru so you can still view your logs in the normal way.
Sadly journalctl (journald control tool) defaults are shit for "usual" browsing of logs and always require throwing some extra commandline options to actually acquire something usable
3
u/listaks Mar 30 '15
You can do
journalctl -fto follow the journal like withtail -f, or dojournalctl -eto automatically jump to the end inless, where you can typeFto start following it.1
u/basilarchia Mar 31 '15
Are there still files in /var/log/ then that are some sort of binary?
Otherwise how do you find out what the names / what logs there are.
Binary log file formats are fucking stupid. No one will every convince me otherwise. OK, I'm not really that jerk, I'm willing to be convinced otherwise.
It's just, to convince me otherwise, we should talk about the myriad of other stupid fucking things in the past that I've seen where you run across some proprietary log file that someone thought was FUCKING awesome to design. Then, you manage to get it off the box and wala! it's total garbage. The pure fact of the matter has always be it took zero pre-knowledge for a person to open a text file. I guess, in the end, that is the ultimate reason that I like for text files.
1
95
u/berkes Mar 30 '15
On a sidenote: I teach people to always use tail -F instead of tail -f. You won't see the difference that often. But when you do, you wish you had started with -F instead.
-F same as --follow=name --retry tail(1).
You'll see the difference when you are tailing that log file to see why the deamon crashes on restart (only to find that on restart it also rotates the logs buy deleting and re-creating: tail stops)
You'll also see the difference when you keep tail running (e.g. in screen) and on re-opening to find you have to restart it.
And mostly, you'll see this breaking when some script or tool uses tail to e.g. monitor something and have that script crash when the log is rotated (poorly).
(edit: inserted some blank lines for legibility)
14
u/rydan Mar 30 '15
I've used -F before but mostly use -f. Will -F close the file handle when the logs are rotated? Sometimes I leave a console open with -f running and the logs rotate but the disk space isn't reclaimed since there is still an open handle until I quit.
49
u/Deewiant Mar 30 '15
Will -F close the file handle when the logs are rotated?
Yes, it will: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c#n1042
11
2
u/berkes Mar 30 '15
I'm not sure about that though. I assumed following the handle meant closing the old one. But never really dove into it.
3
0
Mar 30 '15
Additional few miliseconds of pressing shift and possibility of making
fileFilewhen not caffeinated enough is not worth it0
u/berkes Mar 30 '15
You mean -F will create a file under certain conditions? Never seen that, but I'd love to hear more.
2
Mar 30 '15
No. I meant typing
tail -F Filenameinstead oftail -F filenameby holding shift few ms too long.4
u/berkes Mar 31 '15
If that is where you'd decisions on using flags and arguments lie, I'd advice you to take up some typing lessons instead.
No, I don't use ClassNames in my code, I might type them as CLassNAmes. No miss brown, I'd rather not type your name with capitals, since I might write it as BRown. and i also never capitalise my sentences.
Or maybe you should clean out your keyboard?
-2
Mar 31 '15
well of course you never make any typos ever mr. arrogant fuck
1
u/berkes Mar 31 '15
I'm not saying that.
I am saying that if you choose not to use certain features of software based on the fact you may have problems typing said features, you might want to review your priorities.
→ More replies (1)2
u/das7002 Mar 30 '15
alias tails='tail -F'0
Mar 31 '15
i sonetimes use mine without -f ? -F is almost never useful anyway
4
u/das7002 Mar 31 '15
It's not replacing tail, it's creating an alias tails to be tail -F
→ More replies (3)
29
u/allcentury Mar 30 '15
Tail -f within a tmux pane allows me to search just fine
19
u/qwertyboy Mar 30 '15
But it will still not let you scroll above the original tail.
5
u/CaptSpify_is_Awesome Mar 30 '15
True, but most of the time when I'm doing tail -f, I don't need the entire log. It can even be problematic, like if the original log is really large.
5
u/_riotingpacifist Mar 30 '15
tail -F -n +1
Seriously though, I've been feeling dirty doing that so might use this tip instead
0
u/socium Mar 30 '15
Depends. I fired up Lubuntu 14.04 recently and with the default terminal provided there I remember doing so without a hassle.
7
u/DavidA2001 Mar 30 '15
You can't scroll back in the log file more then the 10? Lines of context tail gives you. You can of course scroll back in your tmux history to see previous commands but you can't look further back in the log file then 10 lines before the moment you invoked tail.
4
u/lennort Mar 30 '15
True, but you can always specify a few more lines for your original context if you know you'll need it later.
tail -n 100 -F filename2
u/DavidA2001 Mar 30 '15
Yes. I think the idea is if you're trying to figure out what's wrong you won't know before you start if you need more context.
I'll admit I go with tail -f initially, but less with S to chop long lines and F to go to the end and follow is what I do of that doesn't immediately clarify things.
1
u/renrutal Mar 31 '15
tail -Fn1000 server1.out -Fn500 server2.logWhen you need only the last 1000 or 500 lines of two different files.
1
u/DavidA2001 Mar 31 '15
Tail wins if you want to open 2 files. The way less handles multiple files is sequential: you can't see them both at the same time.
I just don't think you can usually predict when you'll need more context. And when you find you need more context in this one particular file, you should probably switch to less.
-1
u/petepete Mar 30 '15
ctrl+b [in tmux puts you into pager mode and you can scroll up as far as you want.5
u/irishsultan Mar 30 '15
Not to the lines of the log file that were never printed by tail because they were logged before you started to
tail -f6
28
u/twinkwithnoname Mar 30 '15
I think my project, the Logfile Navigator (http://lnav.org), is an even better alternative to less or tail. In addition to what they do, it does syntax coloring, filtering, loads compressed files, interleaves log messages from multiple files, and more. I would encourage folks to check it out.
7
9
u/Kwpolska Mar 30 '15
Linux binaries? That’s a very unusual way to distribute software.
9
u/twinkwithnoname Mar 30 '15
There are packages for a few distros: Debian, Ubuntu, Gentoo, Fedora, CentOS/SUSE, OS-X's Brew, and MacPorts.
Myself and others find the static binary useful because we often need to get lnav onto a machine we're debugging quickly and easily. Being able to download a static binary to an older system where there's no package readily available is very handy. I also want to make it easy for people to try out.
2
u/Kwpolska Mar 30 '15
I'd recommend promoting system packages upfront. Still, the project certainly looks interesting.
1
u/Freeky Apr 05 '15
FreeBSD port: http://freshports.org/sysutils/lnav
Packages are up too, so just a
pkg install lnavaway \o/0
2
u/gnualmafuerte Mar 30 '15
Your project is nice, but it's not a replacement for tail -f. Neither is less.
The problem with all of those ideas is simple: Not good for large log files. I rotate my apache logs daily, but I have a shitload of traffic. I hate seeing "calculating line numbers" on less or any similar crap. Tail is fast and lightweight, and works equally well on a 10kb file as it does on a 20Gb monstrosity.
1
u/twinkwithnoname Mar 30 '15
Yes, no tool is good in all situations. The front page of the lnav website says as much. I also use tail/grep when the indexing lnav does is not helpful. But, the vast majority of the time, lnav's feature set is very handy when trying to find problems.
1
u/trygveaa Mar 31 '15
Not good for large log files. I rotate my apache logs daily, but I have a shitload of traffic. I hate seeing "calculating line numbers" on less or any similar crap.
You can use
-nto less to disable line numbers, and it will be as fast as tail (not saying you should use less, just that you could).1
Mar 30 '15
Yeah, this is pretty sweet. Got source so I can compile on OpenBSD? Or binaries?
1
u/twinkwithnoname Mar 30 '15
The source is at https://github.com/tstack/lnav . Unfortunately, I haven't tried to compile on OpenBSD yet, I can give it a go sometime soon. The main platforms I use are OS-X and linux so that's where most of my effort goes.
2
u/Freeky Mar 31 '15
Builds fine on FreeBSD. I submitted a port: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=199062
0
Mar 30 '15
[deleted]
2
u/twinkwithnoname Mar 30 '15
Log formats are defined in a json file that you add to a directory in ~/.lnav/formats/ . There's some documentation on the config format here -- http://lnav.readthedocs.org/en/latest/formats.html
Basically, you write a PCRE regex that matches the log messages you're interested in. You can also define the types for the known fields in the message. Take a look at the following sample file to see what the default set of formats looks like:
~/.lnav/formats/default/default-formats.json.sample
If you need help, send a message to the mailing list or file a github issue.
57
u/kairos Mar 30 '15
Stop telling me what to do just because you prefer an alternate tool...
23
u/hothrous Mar 30 '15
I do get tired of people saying "You're doing it wrong because there is a way that I do it and prefer" in the title of their articles. I wish they'd just say, "Here's a good alternative to something that you are doing that you might like"
3
u/badsingularity Mar 30 '15
Use vi or else.
11
7
u/RandomDamage Mar 30 '15 edited Mar 30 '15
My most common use case for tail -f is "tail -f foo.log | grep search_string", which won't work the same with less
That said, this is a pretty neat less trick.
(After reading this, I think I'm going to be using "tail -F foo.log | grep --line-buffered search_string | less" to get all the features!)
[edit] Updated command line due to additional information in response.
5
5
u/tehmatticus Mar 30 '15
To mimic this in less, you can do
less foo.logand then when inside less, hit the&character and type your search string to filter for that string, then hitFto follow the log.1
u/RandomDamage Mar 30 '15
Interesting. After testing I see that you can do multiple filters that way, also.
13
u/dClauzel Mar 30 '15
Better use multitail 😉
12
Mar 30 '15
I call that tmux :p
5
u/_riotingpacifist Mar 30 '15
How do you know figure out if somebody uses a tmux?
You just walk past them and they'll tell you.
2
Mar 30 '15
I thought it'd be because their screen looked like this.
5
u/_riotingpacifist Mar 30 '15
Nobody wastes time making their screen color coordinated, that's the kind of thing tmux users do.
3
u/marx2k Mar 30 '15
...after days and weeks trying to remember key shortcuts to get it like that :)
1
Mar 30 '15
Not really, just a bunch of
C-"andC-%, maybe someC-<space>andC-{orC-}if you buggered where you meant to split.Now windows in Vim...I don't even know. I'll settle for tmux + 2 Vim instances.
1
u/marx2k Mar 30 '15
Was trying to do vertical splits with byobu+screen in MacOS this morning. ...still didn't figure it out.
ctrl-a+| was supposed to make it happen. ctrl-a+% was also an option.
It just wasn't happening and I gave up.
→ More replies (8)1
u/r0ck0 Mar 30 '15
The big red line with timestamp that multitail throws in when you hit enter is awesome.
6
u/tsdgeos Mar 30 '15
Or you can use a terminal emulator application that supports searching and infinite scrollback (konsole does, no idea if others do)
1
u/DavidA2001 Mar 30 '15
Or use screen or tmux from whatever console you want, but you still can't search or view further back into the file then 10 lines before when you invoked tail. You have to C, and open the file in less to see the file from the beginning. That said I still use tail -f mostly and kill it and open less if I need more context.
If I'm running something in a verbose or debug mode specifically to trouble shoot something, I go to less immediately for all of its features.
4
u/port53 Mar 30 '15
but you still can't search or view further back into the file then 10 lines before when you invoked tail.
tail -n+0 -f <file>solves that.
5
u/rydan Mar 30 '15
Interesting. I've always been doing tail -f | less so I guess that solves that problem.
9
u/jellystones Mar 30 '15
I like with tail that you can press "enter" a few times to create a visual reference/gap of the last point you reviewed up to.
3
u/EatMoreCrisps Mar 30 '15
Most of the time I have a better experience by just opening it in Emacs with auto-revert-mode on. Syntax highlighting, search highlighting, all the same editor features...
This will fall down for truly enormous files (I assume the likes of less lets you browse a large file without loading the whole file?). It also only updates by polling. Usually that's fine.
5
Mar 30 '15
Somehow this top post is !+250 right now, and not a single person that I can see in the comments is agreeing that using less +F is better than using tail...
7
u/hothrous Mar 30 '15
Well, it seems people are upvoting for starting a good discussion. Which is what they are for.
4
u/xxczxx Mar 30 '15
Just use a good terminal emulator - like Konsole - and use ctrl+shift+F
2
u/ender_wiggum Mar 30 '15
xterm forever!
1
u/ilgnome Mar 30 '15
gnome-terminal for obvious gnaming conventions.
1
u/ender_wiggum Mar 30 '15
Gnome! http://giphy.com/gifs/harry-potter-surprised-hermione-OzHKDlB6CqwZG
Burn the HERETIC!
5
u/das7002 Mar 30 '15
I see no advantages of using less over tail when nearly everyone uses some kind of shell multiplexer now.
The whole wanting to scroll up and see something is easy as an F7 key away, and as /u/drrlvn stated tail uses inotify, far more resource efficient than an infinite loop that polls for changes. Wait for the kernel to say "hey, this file changed" rather than having the program ask "hey, has this file changed yet?".
And if you aren't using a shell multiplexer yet, stop not using one and go get one now. Whether it's tmux or screen or things that run on top (like byobu), you will fall in love with them, I guarantee it.
1
u/metalbark Mar 30 '15
This.
The distros I've worked on have had multiplexers and/or some kind of terminal + tail/less integration built in such that the less option moot.
And if you aren't using a shell multiplexer yet, stop not using one and go get one now. Whether it's tmux or screen or things that run on top (like byobu), you will fall in love with them, I guarantee it.
Thanks for the recommends. While I love screen I love trying out new stuff as well. This comment should be at the top.
1
u/kynde Mar 30 '15
Whether it's tmux or screen or things that run on top (like byobu), you will fall in love with them, I guarantee it.
And once you've tried tmux, you'll love that more than screen. I guarantee it.
2
u/anotherkeebler Mar 30 '15
The best thing about using less for tailing files is that you can give a search pattern for highlighting interesting lines. I know you can use grep --colour to get the same effect, but that only shows you matching lines, whereas less will let you see the matching line in context.
2
u/runejuhl Mar 30 '15
Well, not quite. If you use grep in the following fashion, you get what you want:
grep -E 'someword|' /tmp/file | lessBe aware that grep may decide to disable colors if the output is piped, so unless you have forced grep to do something else, you have to invoke grep with
--color=alwaysto get the color highlights:grep -E --color=always 'someword|' /tmp/file | less1
u/jroller Mar 30 '15
And "&", which will let you grep within less and then go back to F mode. Unfortunately, & hasn't made it into OSX's less yet.
1
u/tehmatticus Mar 30 '15 edited Mar 30 '15
Because OSX is using the BSD less rather than the GNU Coreutils less. You can install the GNU version via homebrew or macports.
Edit: disregard, less is a self contained project entirely.
1
u/jroller Mar 30 '15
This is hard to tell from the version string:
yosemite $ which less /usr/bin/less yosemite $ less --version less 418 Copyright (C) 1984-2007 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/lessAccording to the less release notes it's only about one version behind (edit: one version behind the & that is). It's interesting that less 418 already changed the license to GPL3, so I assume that won't become more of an issue later.
1
u/tehmatticus Mar 30 '15
Actually I'm entirely wrong. As you pointed out, it's a completely separate project run differently.
I wonder why Yosemite isn't at par with most Linux distros, then.
1
u/Badabinski Mar 30 '15
I believe it's because GPL. I could be wrong, but I think Apple doesn't like using GPLv3 software, hence Clang and all that jazz.
1
u/simtel20 Mar 30 '15
Don't forget that you can stop the ongoing search, then search backwards, and modify your query. E.g. find the match, and look for the most recent prior match, etc.
2
2
2
4
0
u/Sorthum Mar 30 '15
Ctrl-G does this if you invoke less normally.
5
Mar 30 '15 edited Mar 30 '15
Not in my box. I can enable this functionality at will with uppercase "F" key, though (as the article suggests).
1
u/Sorthum Mar 31 '15
...wow, you're right. How'd I screw that one up? Ctrl-G spits out the filename. Sorry about that!
2
Mar 30 '15 edited Jun 29 '15
EDIT*
I have deleted this comment and here is why:
This place claims to be founded on free speech principles. The selective censorship that is happening is worrying, out of control and goes against those principles. Those who may stumble on this comment will see a broken thread, I am very sorry for that. However, that is what censorhip looks like.
Bye bye Reddit.
4
1
u/BillieGoatsMuff Mar 30 '15
I just use ctrl+s to freeze the terminal if i need it to stop or I want to scroll back. and ctrl+q to unfreeze.
2
u/cpbills Mar 30 '15
Unless you have
stty -ixonin your.bashrcbecause you want to useC-sfor forward history search.1
u/BillieGoatsMuff Mar 30 '15
Sure, unless then. but I don't, I would use ctrl+r for (reverse) history search or just history|grep <thing>
1
u/cpbills Mar 30 '15
I dunno about you, but I sometimes use
C-rand overshoot what I'm looking for, or it places me somewhere in my history after the next command I want to run, soC-sis occasionally very handy. Much more than xon / xoff is, especially inscreenortmux.1
u/BillieGoatsMuff Mar 30 '15
I've never noticed an issue with ctrl+r, if it isn't the one i'm after I just it hit again and keep hitting it until it is. Failing that I grep history, like i said. C+s does sound handy though, I'll check it out, thanks. I don't freeze the terminal very often anyway.
1
1
1
u/briellie Mar 30 '15
Or, you could just hit control-s to pause the output, scroll back up through the scroll back and find what you are looking for, then press control-q to resume.
Of course, that only works if you have scrollback buffer enabled and > 0. You could also use screen or tmux, which I believe has its own built in scrollback method.
1
u/hhh333 Mar 31 '15
you can pause/navigate/resume a tail -f instance with Ctrl+s and Ctrl+q.
I still prefer tail or multitail :)
1
u/crashorbit Mar 31 '15
As said elsewhere I use tail -F quite a bit but mostly as a generator in a pipeline such as
tail -F /var/log/messages | perl -MText::Wrap=wrap -nE 'say wrap "", "\t", $_' 1
1
1
0
u/_var_log_messages Mar 30 '15
I know this doesn't really matter but I hate seeing
tailf -fwhen
tailfis the same and saves some time, not much time but still. Must be my Aspergers :/
4
u/taliriktug Mar 30 '15
It comes with util-linux package, and devs decided to deprecate this command due to tail prevalence. Source.
7
u/theinternn Mar 30 '15
I dont have a binary named tailf.
So not the same at all.
1
1
u/merreborn Mar 30 '15
my centos and ubuntu boxes have it, but OS X does not (does BSD?)
3
u/theinternn Mar 30 '15
Yea, it's part of util-linux, not coreutils.
It also is maintained by a different developers, and uses different paradigms. TBH, it's not portable, and doesn't do what I expect, so I have no idea why I'd bother using it.
-1
u/fuckoffplsthankyou Mar 30 '15 edited Mar 31 '15
tail -f /mnt/some/log | less
EDIT: What's with the downvotes? It fucking works.
0
0
Mar 30 '15
[deleted]
4
u/hothrous Mar 30 '15
It depends what I'm looking for. I've used tail -f a lot to just watch a log4j log while a job was processing.
1
u/phessler Mar 31 '15
live logs monitoring.
tail -f /var/log/daemon | grep -E 'bgpd|dhcpd'
shows me only those entries. I let it run while I trigger my tests and/or for a few hours.
18
Mar 30 '15
[removed] — view removed comment
6
u/mioelnir Mar 30 '15 edited Mar 31 '15
lesshas a filter mechanism (I think it is invoked with %it is invoked with&) where only lines matching the filter are displayed. This works for viewing regular files, and I'd assume it also works with thisless +Fmode. In which case you could emulatetail -F | grepwith it, but not in a single invocation. Unless there is a cli option to specify the filter, which I am too tired to look up right now.Edit: thanks to /u/RandCoder for looking up that
&is what I meant. One of those options too rarely used.2
Mar 31 '15
Whoa, another thing I learn today about
less. It's invoked with&. And:hbrings a nice help screen teaching all this cool tricks. :)3
0
u/cpbills Mar 30 '15
You can search within
less, without needing to usegrep, using/<searchpattern>.3
u/RandomDamage Mar 30 '15
That's not the same thing as only displaying the lines that interest you.
1
16
u/[deleted] Mar 30 '15
Why has no one touched on the fact that tail(1) is just the other side of head(1)?
tail, by default, will show the last 10 lines of the file. The ability to follow the file is secondary to this purpose.
Using less and telling it to scroll to the end of the file and refreshing is probably fine on your local system logs. But when you use it on production web server logs which are a couple gigabytes each, it will get stuck at "Calculating line numbers" for an interval that may reach minutes.
I usually just use a combination of
-nand-f, to display the last X lines for context and update on change. If I need to rummage through the file, other measures will be taken.I'll take efficiency over convenience any day of the week. There's a reason I don't dare load these logs in vim, even with syntax highlighting turned off.