Saturday, August 12, 2023

Head Command Example in Linux | How to Use Head Command in Linux

The `head` command in Linux is used to display the beginning lines of a text file. By default, it displays the first 10 lines of a file, but you can specify the number of lines you want to display using the `-n` option. Here are some examples:


1. Display the first 10 lines of a file (default behavior):
   
   head filename.txt
   
2. Display a specific number of lines (e.g., first 20 lines):
   
    head -n 20 filename.txt
   
3. Display the first few lines of multiple files:
   
     head file1.txt file2.txt
   
4. Display the first 5 lines of all `.log` files in a directory:
   
      head -n 5 *.log
   
5. Display the first 15 lines of a remote file using SSH:
   
      ssh user@hostname "head -n 15 /path/to/remote/file.txt"
   
Remember that the `head` command is used to display the beginning lines of a file. If you want to view the ending lines, you can use the `tail` command.


No comments:

Post a Comment

Installing Jenkins on RHEL 8 is a straightforward process. Here's a step-by-step guide

Introduction  Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) pipelines...