Viewing log files without using vi or any other text editor

2010-01-16 129 words 1 min read

This is quite useful for viewing files without opening them.. Saves quite a lot of time in viewing the logs πŸ™‚

Want to see the first 5 lines of the /etc/passwd file? Pretty easy, just use the "head" command:

head -5 /etc/passwd

Want to see the last 20 lines of the /etc/passwd file? Again, pretty easy, just use the "tail" command:

tail -20 /etc/passwd

But what if you only want to see lines 10-15 of a given file? Neither the "head" nor the "tail" commands alone will do. Instead, use the "sed" command to print the range of lines you want to see:

sed -n '10,15p' /etc/passwd

This command works great, even if you want to see a few lines somewhere in the middle of a 100,000 line file.


Tags: Linux

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it