The cut command is most often used to select single columns of data from input separated by a single character, such as an /etc/passwd file. For example, this command line prints the home directories of every user on a GNU/Linux system:
$ cut -d: -f6 /etc/passwd /root /usr/sbin /bin ...
In this example, -d specifies the delimiter or separator variable, in this case a colon, and -f specifies the number of the field (or column), starting from 1.
We can also specify the field numbers with hyphen-separated ranges, and/or comma-separated indices:
$ cut -d: -f1,6 /etc/passwd root:/root daemon:/usr/sbin bin:/bin ... $ cut -d: -f1,3-4 /etc/passwd root:0:0 daemon:1:1 bin:2:2 ...
We can leave one of the numbers out of a range, to mean "up to" or "from":
$ cut -d: -f-2 /etc/passwd root:x daemon:x bin:x ... $ cut -d: -f6- /etc/passwd /root:/bin/bash /usr/sbin:/usr/sbin/nologin /bin:/usr/sbin/nologin
However, cut is not limited to delimited data. It can also split on character counts with -c, or bytes with -b. This can be a useful way to get only a certain number or range of bytes per line:
$ sha256sum .bashrc 50b9745d456e3023a859f3dd2e866e3a3a19a16b0af04b89e3387846fa158206 .bashrc $ sha256sum .bashrc | cut -c-8 50b9745d $ sha256sum .bashrc | cut -c9-16 456e3023a859f3dd