head

Display the first lines of a file.

Syntax
      head [-n count] [file ...]

      head [-c bytes] [file ...]

Key
   -c bytes, --bytes=bytes
       Output the first bytes bytes of each of the specified files.

   -n count, --lines=count
       Print count lines of each of the specified files.

This filter displays the first count lines or bytes bytes of each of the specified files, or of the standard input if no files are specified.

If count is omitted it defaults to 10.

If more than a single file is specified, each file is preceded by a header consisting of the string `==> XXX <==' where `XXX' is the name of the file.

The head utility exits 0 on success, and >0 if an error occurs.

Examples

List the 5 largest subdirectories in the current directory:

du -hs */ | sort | head -n 5

“If you can keep your head when all about you are losing theirs and blaming it on you...” ~ Rudyard Kipling

Related macOS commands

fmt - Reformat paragraph text.
join - Join lines on a common field.
split - Split a file into fixed-size pieces.
tail - Output the last part of files.


 
Copyright © 1999-2024 SS64.com
Some rights reserved