Often we need to display the first or last few lines of a logfile. Normally, we do this for debugging purposes.
Here are a few examples:
This shows the first line
# head -1 logfile
This shows first 5 lines
# head -5 logfile
This shows first 10 lines
# head logfile (default is 10 lines -- no options required)
This shows first 50 lines
# head -50 logfile
This shows first 100 lines
# head -100 logfile
You should get the picture by now
This shows last line
# tail -1 logfile
This shows last 5 lines
# tail -5 logfile
This shows last 10 lines
# tail logfile (this is the default and it shows you the last 10 lines)
This shows last 50 lines
# tail -50 logfile
This shows last 100 lines
# tail -100 logfile
If you want to continuously monitor a logfile, do the following:
# tail -f logfile
This gives you the first line
# sed q logfile
This show you the first 10 lines
# sed 10q logfile
This blog covers Unix system administration HOWTO tips for using inline for loops, find command, Unix scripting, configuration, SQL, various Unix-based tools, and command line interface syntax. The Unix OS supports tasks such as running hardware, device drivers, peripherals and third party applications. Share tips/comments. Read the comments. But most importantly: Read Disclaimer - Read Disclaimer.
Subscribe to:
Post Comments (Atom)
4 comments:
Thanks buddy, sometimes small tips help a lot.
Thanks divya...the comments/tips that transpire after the post is what's really valuable :)
It's great to have all of this in one place. Thanks!
Thanks this was really helpful.
Post a Comment