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
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1The first 10 lines
head /etc/passwdDefault is 10 lines.
2The first 3 lines
head -n 3 /etc/passwdSame as
head -3 /etc/passwd.3Top 5 of a sorted list
The 5 biggest folders in /var.
4Look at the header of a CSV file
head -1 export.csvShows the column names.
5Print line N only
head -n 15 /etc/services | tail -n 1Line 15. Same as
sed -n '15p'.6Everything except the last 2 lines
head -n -2 report.txtRemoves a footer.
7The first bytes of a file
head -c 16 /dev/urandom | base6416 random bytes as text: a quick random token.
8Check a file's start for its type
head -c 4 unknown.bin | xxdPDF files start with %PDF, ELF programs with .ELF.
9The first lines of several files with names
head -n 2 /etc/*-releaseEach file gets a
==> name <==header.10The top processes by memory
ps aux --sort=-%mem | head -6The header plus the 5 biggest.
11Read the start of a huge log quickly
head -n 50 /var/log/huge.loghead stops reading after 50 lines, so it is fast even on big files.
Niets past bij dit filter.
Tips om te onthouden
- head = top, tail = bottom.
head -n N | tail -n 1= line N.