Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

head

Show the first lines (or bytes) of files or command output.

Niveau
RHCSA-examen
Groep
Tekst en zoeken
Root nodig
Nee
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

head prints the first 10 lines of each file. With -n you choose how many. With a minus number (-n -5) it prints everything except the last 5 lines.

It is perfect for a quick look at a file, the header of a CSV file, or the top of a sorted list.

Zo schrijf je het

head [OPTION]... [FILE]...

Opties 8

Meest gebruikt

-n, --lines=[-]num
Print the first NUM lines. With a minus: all lines except the last NUM.
-c, --bytes=[-]num
Print the first NUM bytes (K, M suffixes allowed). With a minus: all but the last NUM bytes.
-num
Old short form of -n NUM (like head -5).
-q, --quiet, --silent
Do not print the file name headers.
-v, --verbose
Always print the file name headers.
-z, --zero-terminated
Lines end with NUL, not a new line.
--help
Show help.
--version
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1The first 10 lines

    head /etc/passwd

    Default is 10 lines.

  2. 2The first 3 lines

    head -n 3 /etc/passwd

    Same as head -3 /etc/passwd.

  3. 3Top 5 of a sorted list

    du -sh /var/* 2>/dev/null | sort -rh | head -5

    The 5 biggest folders in /var.

  4. 4Look at the header of a CSV file

    head -1 export.csv

    Shows the column names.

  5. 5Print line N only

    head -n 15 /etc/services | tail -n 1

    Line 15. Same as sed -n '15p'.

  6. 6Everything except the last 2 lines

    head -n -2 report.txt

    Removes a footer.

  7. 7The first bytes of a file

    head -c 16 /dev/urandom | base64

    16 random bytes as text: a quick random token.

  8. 8Check a file's start for its type

    head -c 4 unknown.bin | xxd

    PDF files start with %PDF, ELF programs with .ELF.

  9. 9The first lines of several files with names

    head -n 2 /etc/*-release

    Each file gets a ==> name <== header.

  10. 10The top processes by memory

    ps aux --sort=-%mem | head -6

    The header plus the 5 biggest.

  11. 11Read the start of a huge log quickly

    head -n 50 /var/log/huge.log

    head stops reading after 50 lines, so it is fast even on big files.

Tips om te onthouden

  • head = top, tail = bottom. head -n N | tail -n 1 = line N.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man head