Skip to content

cut command

Cut out columns or characters from each line.

On this page

Syntax

cut [options] [file…]

Provided by the coreutils package. Run man cut for the full manual.

Common options

OptionWhat it does
-d SEPField delimiter (default tab)
-f LISTFields to keep, e.g. 1,3 or 2-4
-c LISTCharacters to keep
--complementKeep everything except the selected fields
--output-delimiter=STRDelimiter in the output

Examples

  1. Usernames from /etc/passwd

    cut -d: -f1 /etc/passwd
  2. Columns 1 and 3 of a CSV

    cut -d, -f1,3 data.csv
  3. First 8 characters of each line

    cut -c1-8 file.txt
  4. Everything except column 2

    cut -d, -f2 --complement data.csv
  5. Hostname part of a FQDN

    echo "web1.example.com" | cut -d. -f1

Tips

  • cut can't handle runs of spaces; use awk for space-separated output.

cut guides

← All Linux commands · Suggest a fix

Back to top