head usage example
Usage
Here’s how to use head:
-
Enter the
headcommand followed by the file name you want to view:head /var/log/auth.logThis will print the first ten lines of the
/var/log/auth.logfile to your terminal output. -
To change the number of lines displayed, use the
noption:head -n 50 /var/log/auth.logIn this example, the first 50 lines will be shown, but you can modify this number to show as few or as many lines as you need.
-
To show the beginning of a file up to a specific number of bytes, you may use the
coption:head -c 1000 /var/log/auth.logThis will print the first 1000 bytes of the file to your screen. It can be useful in situations where a file must be broken into pieces of a fixed size (e.g., for uploading to a separate server).
-
The
headcommand can even be combined with other tools likegrepto filter the results:head /var/log/auth.log | grep 198.51.100.1This command searches the first ten lines of your access log and only displays those containing the IP address
198.51.100.1. You can also apply options toheadfor an even more specific output.
https://www.linode.com/docs/guides/how-to-use-head/
Some of the content is generated by AI, please be cautious in identifying it.