What it does
cut prints selected parts of every line. With -d you give the separator (one character) and with -f the field numbers. With -c you select characters by position.
It is ideal for files with a fixed separator like /etc/passwd (:) or CSV (,). For columns separated by a varying number of spaces, awk is better.
How to write it
cut OPTION... [FILE]...Options 15
Most used
LIST forms
Nothing matches this filter.
Examples 11
$ run as a normal user# run as root (or with sudo)
1All user names
cut -d: -f1 /etc/passwdField 1 of /etc/passwd is the user name.
2User name and shell
cut -d: -f1,7 /etc/passwd root:/bin/bashFields 1 and 7, still joined by
:.3The first 8 characters of each line
cut -c1-8 /etc/passwdCharacter positions, not fields.
4Columns of a CSV file
cut -d, -f2,4 users.csvFields 2 and 4 (note: quoted commas inside fields break this; use a CSV tool then).
5Everything except field 2
cut -d: -f2 --complement /etc/passwdRemoves the password placeholder column.
6Change the output separator
cut -d: -f1,6 --output-delimiter=' -> ' /etc/passwd root -> /rootReadable output for a report.
7Only the group names
cut -d: -f1 /etc/group | sortAll local groups, sorted.
8Get the IP address part of an address/prefix
cut -d/ -f1removes the/24.9Field 3 to the end
cut -d' ' -f3- server.logDrops the date and time columns of a log line.
10Skip lines without the separator
cut -d= -f2 -s app.confComment lines without
=are not printed.11The size column of a TAB separated report
TAB is the default separator.
Nothing matches this filter.
Watch out
Tips to remember
cut -d: -f1= first column of passwd-style files.