Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

head (Unix)

From Wikipedia, the free encyclopedia
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Head" Unix – news ·newspapers ·books ·scholar ·JSTOR
(June 2020) (Learn how and when to remove this message)
Program on Unix and Unix-like systems


head
Example usage ofhead command to display first 5 lines ofLorem ipsum in the specified file
DevelopersVariousopen-source andcommercial developers
Operating systemUnix,Unix-like,MSX-DOS,IBM i
PlatformCross-platform
TypeCommand
Licensecoreutils:GPLv3

head is aprogram onUnix andUnix-likeoperating systems used to display the beginning of a textfile orpiped data.

Syntax

[edit]

The commandsyntax is:

head [options]⟨file_name⟩

By default,head will print the first 10 lines of its input to thestandard output.

Option flags

[edit]
-n⟨count⟩
--lines=⟨count⟩
The number of lines printed may be changed with acommand line option. The following example shows the first 20 lines offilename:
head -n 20filename

This displays the first 5 lines of all files starting withfoo:

head -n 5foo*
Most versions[citation needed] allow omittingn and instead directly specifying the number:-5.GNU head allows negative arguments for the-n option, meaning to print all but the last - argument value counted - lines of each input file.
-c⟨bytes⟩
--bytes=⟨bytes⟩
Print first x number of bytes.

Other command

[edit]

Many early versions of Unix and Plan 9 did not have this command, and documentation and books usedsed instead:

sed 5qfilename

The example prints every line (implicit) and quit after the fifth.

Equivalently,awk may be used to print the first five lines in a file:

awk 'NR < 6'filename

However, neither sed nor awk were available in early versions ofBSD, which were based onVersion 6 Unix, and included head.[1]

Implementations

[edit]

Ahead command is also part ofASCII'sMSX-DOS2 Tools forMSX-DOS version 2.[2] Thehead command has also been ported to theIBM i operating system.[3]

See also

[edit]

References

[edit]
  1. ^Spinellis, Diomidis (2022)."dspinellis/unix-history-man: Version 1.0 web pages (v1.1-web)".Zenodo.doi:10.5281/zenodo.7248228.
  2. ^MSX-DOS2 Tools User's Manual by ASCII Corporation
  3. ^IBM."IBM System i Version 7.2 Programming Qshell"(PDF).Archived(PDF) from the original on 2020-09-18. Retrieved2020-09-05.

External links

[edit]
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Text utilities
Shell utilities
Retrieved from "https://en.wikipedia.org/w/index.php?title=Head_(Unix)&oldid=1336332509"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp