2

I am ssh'd into a server and want to traverse through long log (5000 lines).

what is the best command to do this?

I tried tail -2000 server.log

but then I have to scroll up my SSH window....which only goes up a little.

I cant install anything new on the server..

4 Answers4

3

Try less server.log or zless server.log.1.gz for the compressed logs.

3dinfluence
  • 12,479
2

I'm partial to:

tail -2000 server.log | more

Or if I know specifically what I'm looking for:

grep -i somesearchstring [| more]

Or if I just want to watch the log go by:

tail -f server.log

because, well, you know, logs are fun to just watch go by.

squillman
  • 38,013
  • 1
    Piping a command's output into more or less ( | more ) has to be one of the most important *nix command line features to know. As squillman pointed out you can go from tail or grep, you can also go from ls, cat and any other command that normally sends its output to the console if you need the ability to scroll through the output. – ManiacZX Jan 22 '10 at 18:23
  • Yeah piping is a core concept that every *nix admin should know. I was going to mention it in my answer but I got pulled away from my desk so I just posted what I had already written. I tend to use less rather than more though. Less is the new more. – 3dinfluence Jan 22 '10 at 20:28
1

Nothing wrong with using tail, but you need to add | more on the end.

For example:

tail -2000 /var/log/messages | more 

That'll make it so you have to hit return to move to the next screen. Less and More are well and good, but who wants to page down through a 200,000 line file?

Satanicpuppy
  • 5,965
0

Other pagers include more, most and pg.