Tested on Ubuntu 22.04 / 24.04 and Debian 12
The cut command is a standard Linux utility used to extract specific sections from each line of a file or command output. It works well for simple, structured text where columns are separated by fixed positions or delimiters.
Typical use cases include:
- Extracting columns from text files
- Parsing delimited data such as CSV-like output
- Filtering command output in shell pipelines
cut Command - Quick Cheat Sheet
| Task | cut Command |
|---|---|
| Extract specific characters from each line | cut -c 1-5 filename |
| Extract specific byte positions | cut -b 1-10 filename |
| Extract a single column from file | cut -f 1 filename |
| Extract multiple columns | cut -f 1,3 filename |
| Extract range of columns | cut -f 2-4 filename |
| Use custom delimiter | cut -d ':' -f 1 /etc/passwd |
| Extract username from passwd file | cut -d ':' -f 1 /etc/passwd |
| Extract column from CSV file | cut -d ',' -f 2 data.csv |
| Extract characters from command output | command | cut -c 1-10 |
| Exclude selected field (complement) | cut --complement -f 2 file.txt |
| Suppress lines without delimiter | cut -s -d ':' -f 1 file |
| Combine cut with pipes | ps aux | cut -c 1-20 |
| Extract fields and change delimiter | cut -d ':' -f 1,3 --output-delimiter=' ' |
| Use cut in pipeline | `ps aux |
| Display cut version | cut --version |
| Display help message | cut --help |
This quick reference summarizes the most commonly used cut command examples in Linux for extracting specific columns, fields, or character ranges from files and command output.
How the cut command works
The cut command operates on bytes, characters, or fields. One of these must be specified for the command to work.
Supported selection formats:
N→ select the Nth byte, character, or fieldN-M→ select from position N to MN-→ select from position N to the end-M→ select from the beginning up to position M
General syntax:
cut OPTION... [FILE]...Selecting bytes with cut command
Extract specific bytes
cut -b 1 file.txtExtracts only the first byte from each line of the file.
Byte positions start from 1, not zero.
This is useful for fixed-format files where each column occupies a known byte offset.
Extract a range of bytes
cut -b 4-11 file.txtExtracts bytes starting from position 4 through 11 on each line.
You can also extract non-contiguous byte positions by separating them with commas.
cut -b 1,3,5 file.txtThis prints only the selected byte positions, in the order specified.
Selecting characters from text
Extract specific characters
cut -c 2-12 file.txtExtracts characters from position 2 through 12 on each line.
Spaces and TAB characters are counted as single characters, and character positions are counted from 1.
This is commonly used for trimming prefixes or extracting portions of text lines.
Selecting fields using delimiters
Extract fields using default delimiter (TAB)
By default, cut treats the TAB character as the field delimiter.
cut -f 1 file.txtExtracts the first field from each line.
If a line does not contain a TAB, the entire line is printed as-is. This behavior is important to understand when working with mixed input.
Use a custom field delimiter
Use the -d option to specify a delimiter other than TAB.
The delimiter must be a single character.
cut -d ':' -f 1 /etc/passwdExtracts the first field from /etc/passwd, where fields are separated by colons.
This is commonly used for parsing:
- user databases
- log files
- colon- or comma-separated text
Extract multiple fields
You can extract more than one field by separating field numbers with commas.
cut -d ':' -f 1,3 /etc/passwdThis extracts the first and third fields from each line.
Fields are printed in the order specified.
Extract a range of fields
You can extract a continuous range of fields using a hyphen.
cut -d ':' -f 1-3 /etc/passwdExtracts fields 1 through 3 from each line.
To select from a field position to the end:
cut -d ':' -f 3- /etc/passwdPrint only lines containing the delimiter
By default, cut prints lines even if the delimiter is missing.
Use the -s option to suppress such lines.
cut -d ':' -f 1 -s file.txtOnly lines containing the delimiter are printed. This is useful when filtering noisy or inconsistent input.
Limitation when using spaces as delimiters
The cut command treats each character literally.
This means it cannot handle multiple consecutive spaces as a single delimiter.
cut -d ' ' -f 1 file.txtIf your input uses variable-width spaces, prefer tools like awk instead.
Working with ranges and complements
Range and complement options allow you to fine-tune exactly which parts of each line are included or excluded in the output.
These options work with bytes (-b), characters (-c), and fields (-f).
Select from a position to the end
Use this form when you want everything from a specific position onward.
cut -c 5- file.txtPrints characters starting from position 5 to the end of each line.
Select from the beginning to a position
Use this form when you want everything up to a specific position.
cut -c -10 file.txtPrints characters from the beginning of the line up to position 10.
Combine multiple ranges
You can combine multiple ranges and positions using commas.
cut -c 1-5,10-15 file.txtThis extracts characters 1–5 and 10–15 from each line.
Ranges are processed in the order specified.
Exclude selected output using complement
Use --complement to print everything except the selected portion.
cut --complement -f 2 file.txtPrints all fields except the second field.
The --complement option works with -b, -c, and -f.
Using cut in pipelines
Extract columns from command output
Use cut to extract fixed-width columns from commands that produce aligned output.
ps aux | cut -c 1-20This extracts the first 20 characters from each line of process output.
Process delimited output from other commands
Use field-based selection when command output is delimiter-separated.
df -h | cut -d ' ' -f 1This extracts the filesystem column from disk usage output.
Note: If the delimiter appears multiple times (such as variable spaces), tools like
awkmay be more reliable.
Combine cut with grep for filtering
cut works well after filtering input with grep.
ps aux | grep root | cut -c 1-30This filters processes owned by root and then extracts relevant columns.
Combine cut with sort or uniq
Use cut to extract a column before sorting or deduplicating data.
cut -d ':' -f 1 /etc/passwd | sort | uniqThis extracts usernames and removes duplicates.
Summary
The cut command in Linux is a fast and simple tool for extracting specific parts of text. It is ideal for byte, character, and field-based selection in scripts and command pipelines. Understanding delimiters, ranges, and complements allows you to handle most everyday text-processing tasks efficiently.
Also Read
- awk command examples in Linux
- Sort files in Linux using sort command
- grep command in Linux with practical examples









