Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Text Processing

Linux cut command

Reference for the Linux cut command: extract fields with -d and -f, characters with -c, bytes with -b, ranges, complement and the limits of cut with spaces.

cut extracts parts of every line of its input: selected fields separated by a delimiter (-f), selected character positions (-c) or selected bytes (-b). It is a small, fast tool for tables with a clear separator, such as /etc/passwd, CSV without quoting, or fixed-width output.

cut does not reorder: fields always come out in their original order, no matter how you list them. For rearranging or for variable whitespace use awk.

Terminal
cut OPTION... [FILE]...

Try it

Bash Fields with a delimiter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Characters, bytes and pipelines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
cut -b LIST [FILE]...
cut -c LIST [FILE]...
cut -f LIST [-d DELIM] [-s] [FILE]...

LIST is a comma-separated set of numbers and ranges, counted from 1: 3, 1,4, 2-5, -3 (up to 3), 4- (from 4).

Option Description
-f LIST Select fields.
-d DELIM Field delimiter, a single character (default tab).
-s, --only-delimited With -f, skip lines that contain no delimiter.
-c LIST Select characters by position.
-b LIST Select bytes by position.
--complement Print everything except the selected parts.
--output-delimiter=STR Join selected fields with STR instead of the input delimiter.
-z Lines end with NUL.

Returns: 0 on success, 1 on a usage error or unreadable file.

Usage notes

  • One delimiter character only. -d', ' (comma and space) is an error. Convert multi-character separators first with sed or tr.
  • Repeated delimiters make empty fields. a b with -d' ' has fields a, empty, b. Squeeze runs with tr -s ' ' or use awk '{print $2}', which splits on any run of blanks.
  • Order cannot change: cut -f3,1 prints field 1 then field 3. Use awk -F: '{print $3, $1}' or paste with separate cuts to reorder.
  • Quoted CSV ("a,b",c) is not understood. cut splits at every delimiter even inside quotes. Use a real CSV parser for those files.
  • Multibyte text. GNU cut may still count bytes for -c, so a multibyte UTF-8 character can be split. Test with an accented letter before relying on -c for non-ASCII data, or use awk with a UTF-8 aware implementation.
  • Lines with too few fields give an empty line for -f5 when the line has a delimiter, and the whole line when it has none (unless -s).
  • Trailing newline is preserved per line; an unterminated last line is printed with a newline added.
  • Typical combination: cut -d: -f7 /etc/passwd | sort | uniq -c counts login shells.