Text processing

Linux cut command

Extract selected fields or character ranges from each input line.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

cut OPTION... [FILE]...

Examples

Print the first colon-separated field from each line.

cut -d: -f1 /etc/passwd

Print characters 1 through 12 from each line.

cut -c1-12 names.txt

Parameters, options and clauses

Option / clauseDescription
-b, --bytes=LISTSelect byte positions.
-c, --characters=LISTSelect character positions.
-d, --delimiter=DELIMUse DELIM as the field delimiter (default tab).
-f, --fields=LISTSelect fields; requires delimiter-separated input.
-s, --only-delimitedSkip lines without the delimiter.
--complementSelect the complement of the chosen bytes, characters or fields.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory