Skip to content

Obscure Command of the Day: head

Today’s obscure command is the head command. While not as obscure as some of the others mentioned in this series, it is still a command I have almost never used. head is the opposite of tail, which is a frequently used command, especially when using the ‘-f’ option. When you use tail -f, it will loop and continually show the last 10 lines of the presumably growing file, which is especially useful when you are monitoring a log file.

head, in fact, does exactly what you might imagine the opposite of tail does - show the first n (by default 10) lines of a file. This would be a useful command for a batch file, as usually if I want to look at the first few lines of a file, I will use either the old fashioned more command or the new fangled less command, which gives you lots of option when invoked interactively (like searching for things). But if you wanted to check the beginning of a file (particularly if it was a huge file and you knew your string was at the beginning) for some particular string, piping the output of head to grep would be a very handy process.

Post a Comment

Your email is never published nor shared.