16

I want to know what is the command to display the last TEN lines in file: /var/log/syslog

  • 1
    Welcome to Ask Ubuntu! @user260487: If my answer was helpful to you, then please consider marking it as the accepted answer so others may more easily find it in the future. This is also a polite way to thank the person answering your question for helping you out. – Danatela Mar 21 '14 at 9:27
32

Try

tail /var/log/syslog

Example:

$ tail /var/log/syslog
Mar 21 11:41:32  whoopsie[1194]: last message repeated 15 times
Mar 21 11:42:32  whoopsie[1194]: last message repeated 20 times
Mar 21 11:43:32  whoopsie[1194]: last message repeated 16 times
Mar 21 11:44:32  whoopsie[1194]: last message repeated 14 times
Mar 21 11:45:32  whoopsie[1194]: last message repeated 11 times
Mar 21 11:46:32  whoopsie[1194]: last message repeated 16 times
Mar 21 11:47:32  whoopsie[1194]: last message repeated 15 times
Mar 21 11:48:32  whoopsie[1194]: last message repeated 14 times
Mar 21 11:49:32  whoopsie[1194]: last message repeated 16 times
Mar 21 11:50:32  whoopsie[1194]: last message repeated 22 times

For default, tail shows last 10 lines of input file. To display more, there is an option -n.
From man tail:

-n, --lines=K
       output the last K lines, instead of the last 10; or use -n +K to
       output lines starting with the Kth

For example:

$ tail -n 15 /var/log/syslog
Mar 21 11:56:45 Karimov-Danil named[1122]: error (network unreachable) resolving './DNSKEY/IN': 2001:dc3::35#53
Mar 21 11:56:45 Karimov-Danil named[1122]: error (network unreachable) resolving './NS/IN': 2001:dc3::35#53
Mar 21 11:56:48 Karimov-Danil named[1122]: managed-keys-zone: Unable to fetch DNSKEY set '.': timed out
Mar 21 11:56:51 Karimov-Danil whoopsie[1194]: online
Mar 21 11:57:54  whoopsie[1194]: last message repeated 17 times
Mar 21 11:58:58  whoopsie[1194]: last message repeated 16 times
Mar 21 12:00:03  whoopsie[1194]: last message repeated 10 times
Mar 21 12:01:03  whoopsie[1194]: last message repeated 16 times
Mar 21 12:02:03  whoopsie[1194]: last message repeated 10 times
Mar 21 12:03:03  whoopsie[1194]: last message repeated 17 times
Mar 21 12:04:03  whoopsie[1194]: last message repeated 14 times
Mar 21 12:05:03  whoopsie[1194]: last message repeated 17 times
Mar 21 12:06:03  whoopsie[1194]: last message repeated 13 times
Mar 21 12:07:04  whoopsie[1194]: last message repeated 16 times
Mar 21 12:08:04  whoopsie[1194]: last message repeated 16 times
  • The answer is correct, but can you expand it. Tell about tail more. For example tail -15 /var/log/syslog will show last 15 lines etc... – c0rp Mar 21 '14 at 6:02
1

tail is the way to go, however in case for whatever reason you don't have tail, you can use tac + awk

tac input.txt | awk 'NR <=10' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.