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 reference (most used options)
| Task | Command |
|---|---|
| Extract specific bytes | cut -b 1 file.txt |
| Extract range of bytes | cut -b 4-11 file.txt |
| Extract specific characters | cut -c 2-8 file.txt |
| Extract fields (TAB-delimited) | cut -f 1 file.txt |
| Extract fields using custom delimiter | cut -d ':' -f 1 file.txt |
| Extract multiple fields | cut -d ',' -f 1,3 file.txt |
| Select from Nth position to end | cut -c 5- file.txt |
| Select from start to Mth position | cut -c -10 file.txt |
| Suppress lines without delimiter | cut -d ':' -f 1 -s file.txt |
| Exclude selected field (complement) | cut --complement -f 2 file.txt |
| Use cut in pipeline | `ps aux |
| Display cut version | cut --version |
| Display help message | cut --help |
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.txt
Extracts 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.txt
Extracts 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.txt
This prints only the selected byte positions, in the order specified.
Selecting characters from text
Extract specific characters
cut -c 2-12 file.txt
Extracts 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.txt
Extracts 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/passwd
Extracts 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/passwd
This 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/passwd
Extracts fields 1 through 3 from each line.
To select from a field position to the end:
cut -d ':' -f 3- /etc/passwd
Print 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.txt
Only 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.txt
If 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.txt
Prints 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.txt
Prints 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.txt
This 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.txt
Prints 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-20
This 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 1
This 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-30
This 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 | uniq
This 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

