Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Unix, how can I display the first few lines of a file?

Use the Unix head command to read the first few lines of an input file and send them to standard output (i.e., your terminal screen). The format for the head command is:

head -lines filename

In this example, lines is an optional value specifying the number of lines to be read. If you don't give a number, the default value of 10 is used. Also, filename represents the name of an optional file for the head command to read. Otherwise, it will take its input from stdin (standard input: the terminal, or whatever the shell feeds the process with, usually pipe output).

For example, given a file containing the English alphabet with each letter on a separate line, a user enters the command:

head -3 alphabetfile

This command would return:

a b c

You can also use the head command with pipes. For example, to see the sizes of the first few files in a large directory, you could enter at the Unix prompt:

ls -l | head

To save this information into a file in the current directory named mylist, you could enter:

ls -l | head > mylist

For more information, consult the Unix manual page by entering at the Unix prompt:

man head

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document acri in domain all.
Last modified on December 18, 2008.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.