Header Ads

Breaking News

How to use the head and tail commands: 2-Minute Linux Tips

Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the head and tail commands. They’re basic commands that every Linux user should know.
The head command is generally used to display the top lines in a text file. For example, you can see the top 10 lines of the words file with a command like this:
If you want to see more or fewer lines, specify the line count you want like this:
The tail command does the opposite. It shows the last lines in a file:
You can also pipe the output of other commands to head or tail. For example, to see the most recently updated files in your home directory, you could use a command like this:
The “ls -ltr” command lists my files in reverse order (the most recently updated last), and the tail command displays only the bottom of that listing.
Both commands also allow you to select the number of characters (rather than lines) to be displayed. These commands display the first 10 and last 6 characters in the words file with a string of = signs separating them:

Note that you’re only seeing 6 characters in the last line because the 6th character is a linefeed.
That’s your Linux tip for the head and tail commands.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.

Source Link

No comments