Cut Command in Linux: Extract Columns, Fields, and Characters
Learn cut command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
9 min read
Learn cut command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What cut Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
Learning how to use the cut command in linux gives system administrators and developers a fast, lightweight utility for column-oriented text extraction. Standardized in POSIX and pre-installed as part of GNU coreutils on every Linux distribution, cut is specifically designed to slice horizontal lines of text into vertical slices based on byte positions, character offsets, or delimiter-separated fields.
The cut command in Linux extracts sections, columns, or fields from each line of files or standard input, writing the extracted data to standard output. Run cut -d: -f1 /etc/passwd to extract all usernames from the system password file, or cut -c1-10 file.txt to slice the first 10 characters of each line.
While general-purpose scripting languages like Python or text engines like awk can parse tabular data, cut excels in shell pipelines due to its simplicity, near-zero startup time, and minimal memory usage. When you need to grab the first column of a colon-separated file, extract fixed-width log timestamps, or isolate specific fields from CSV/TSV exports, cut performs the task with unmatched speed.
Understanding cut's selection modes—specifically the distinctions between bytes (-b), characters (-c), and fields (-f)—along with output delimiter manipulation ensures your shell pipelines remain clean, deterministic, and resilient against unexpected line formats.
What cut Does and When to Use It
Internally, GNU cut reads input sequentially through standard I/O buffer streams. When operating in field mode (-f), cut scans each line byte-by-byte looking for the single-byte delimiter specified by -d (defaulting to the tab character \t). As delimiters are encountered, an internal field index counter increments; if the index matches one of the requested field ranges, the slice is copied to stdout, separated by the output delimiter (which defaults to the input delimiter unless overridden by --output-delimiter).
When operating in byte (-b) or character (-c) mode, cut tracks byte and multibyte offsets from the start of each line. In multibyte UTF-8 locales, GNU coreutils cut uses mbrtowc(3) or specialized UTF-8 decoders to count valid character boundaries when invoked with -c, ensuring multibyte characters are not sliced in half. By maintaining pre-allocated integer bitmasks for field and character ranges, cut evaluates arbitrary column lists (e.g. -f1,3-5,9) in a single linear pass per line without dynamic memory reallocation.
Under the hood, cut gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as -d DELIM, -f LIST, -c LIST, -b LIST turns raw process and service tables into actionable diagnostics during incident response.
Availability and Installation Across Linux Distributions
The cut utility is packaged in coreutils across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether cut is installed and inspect which binary path and version your shell resolves:
type -a cut
cut --version 2>/dev/null || man -f cut
# Illustrative output (reviewed against documentation)
cut is /usr/bin/cut
cut (coreutils)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y coreutils
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y coreutils
# Arch Linux
sudo pacman -S --noconfirm coreutils
# Alpine Linux
sudo apk add --no-cache coreutils
Command Syntax, Arguments, and Exit Status Codes
cut OPTION... [FILE...]
The general invocation syntax is cut OPTION... [FILE...]. cut requires you to specify exactly one of three primary selection modes: -b (bytes), -c (characters), or -f (fields). Slicing ranges are specified as comma-separated lists and hyphenated ranges (e.g. 1,3,5 or 1-4 or 5-).
When using field mode (-f), the delimiter option -d must be supplied if the file is not tab-separated. By default, cut prints lines that do not contain the delimiter unless the -s (--only-delimited) flag is passed. If no FILE arguments are provided, cut reads continuously from standard input (stdin).
0— Successful completion; all specified slices extracted without error.1— Operational failure; file unreadable, permission denied, or write error.2— Syntax error; conflicting options (e.g. specifying both -c and -f) or invalid range.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
-d DELIM | --delimiter=DELIM | Use DELIM instead of TAB for field delimiter (must be a single character). |
-f LIST | --fields=LIST | Select only these fields; also print any line that contains no delimiter character unless -s. |
-c LIST | --characters=LIST | Select only these characters (ranges like 1-5, 8, 12-). |
-b LIST | --bytes=LIST | Select only these bytes (ignores multibyte boundaries). |
-s | --only-delimited | Do not print lines that do not contain delimiter characters. |
--complement | --complement | Invert the selection: output all fields, bytes, or characters EXCEPT the selected ones. |
--output-delimiter=STRING | --output-delimiter=STRING | Use STRING as the output field delimiter instead of the input delimiter. |
--help | --help | Display help documentation and exit. |
The -s (--only-delimited) option is vital when parsing structured files that contain comments or blank lines. Without -s, cut prints every line that lacks the delimiter in its entirety, which can pollute output with headers or section dividers.
The --complement flag provides an elegant way to drop specific columns without writing long range lists. For example, cut -d: -f2 --complement /etc/passwd prints all fields EXCEPT field 2 (the password placeholder 'x'), preserving the rest of the record structure.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. Extract Usernames from /etc/passwd
Extract the first column (username) from the colon-delimited system user database.
cut -d: -f1 /etc/passwd | head -n 4
# Illustrative output (reviewed against documentation)
root
daemon
bin
sys
Setting -d: tells cut to split by colon, while -f1 extracts the first field.
2. Extract Multiple Non-Contiguous Fields
Extract the username ($1), UID ($3), and login shell ($7) from /etc/passwd.
cut -d: -f1,3,7 /etc/passwd | head -n 3
# Illustrative output (reviewed against documentation)
root:0:/bin/bash
daemon:1:/usr/sbin/nologin
bin:2:/usr/sbin/nologin
Comma-separated indices (-f1,3,7) extract multiple specific fields in their original order.
3. Slice Fixed-Width Log Lines by Character Positions
Extract the timestamp (first 19 characters) from standardized system log entries.
cut -c1-19 /var/log/dpkg.log | head -n 3
# Illustrative output (reviewed against documentation)
2026-10-20 14:02:11
2026-10-20 14:02:12
2026-10-20 14:02:15
The -c1-19 range extracts character offsets 1 through 19 from every line.
4. Suppress Lines Without Delimiters with -s
Parse key-value properties while automatically ignoring comments and section headers.
cat << 'EOF' > config.ini
# Server Configuration
port=8080
workers=4
# End of File
EOF
cut -s -d= -f1 config.ini
# Illustrative output (reviewed against documentation)
port
workers
The -s flag omits lines lacking the '=' delimiter, stripping comments cleanly.
5. Change the Output Delimiter Using --output-delimiter
Extract fields from a colon-separated file and format them as comma-separated values (CSV).
cut -d: -f1,3,6 --output-delimiter="," /etc/passwd | head -n 3
# Illustrative output (reviewed against documentation)
root,0,/root
daemon,1,/usr/sbin
bin,2,/bin
The --output-delimiter option replaces the input colon delimiter with a comma.
6. Invert Column Selection Using --complement
Print all columns from a CSV file except the sensitive third column.
cat << 'EOF' > data.csv
ID,Name,SSN,Department
101,John,000-11-2222,Engineering
102,Sara,333-44-5555,Finance
EOF
cut -d, -f3 --complement data.csv
# Illustrative output (reviewed against documentation)
ID,Name,Department
101,John,Engineering
102,Sara,Finance
The --complement flag inverts the selection, dropping field 3 while retaining fields 1, 2, and 4.
Real-World Workflows, Pipelines, and Shell Automation
Security Audit: Enumerating Users with Active Interactive Shells
Parse /etc/passwd to list all human user accounts configured with interactive login shells.
#!/usr/bin/env bash
set -euo pipefail
echo "=== System Accounts with Interactive Shell Access ==="
cut -d: -f1,3,7 /etc/passwd \
| grep -v -E '(/nologin|/bin/false)$' \
| while IFS=: read -r user uid shell; do
printf "User: %-14s | UID: %-5s | Shell: %s\n" "$user" "$uid" "$shell"
done
# Illustrative output (reviewed against documentation)
=== System Accounts with Interactive Shell Access ===
User: root | UID: 0 | Shell: /bin/bash
User: ubuntu | UID: 1000 | Shell: /bin/bash
User: deploy | UID: 1001 | Shell: /bin/zsh
This workflow uses cut to extract relevant columns, pipes into grep to filter out system nologin shells, and formats the output.
Network Diagnostics: Extracting Bound IPv4 Addresses from Socket Telemetry
Parse listening socket outputs from ss to generate a clean list of bound local IP addresses.
#!/usr/bin/env bash
set -euo pipefail
echo "Extracting listening local port bindings..."
ss -tuln \
| awk 'NR>1 {print $5}' \
| cut -d: -f1 \
| sort -u
# Illustrative output (reviewed against documentation)
Extracting listening local port bindings...
0.0.0.0
127.0.0.1
127.0.0.53
Combining awk and cut isolates IP addresses before the port delimiter, producing a unique list of listening interfaces.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding cut inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
cut does not alter input files. However, redirecting cut output into the same input file (e.g. cut -d: -f1 file.txt > file.txt) will instantly truncate file.txt to 0 bytes before cut can process it. Always redirect to a temporary file.
cut does not support multi-character delimiters or complex quoting rules. Slicing CSV files containing escaped commas within quotes (e.g. "San Francisco, CA",USA) will produce misaligned columns, potentially exposing or misrouting sensitive data in automated pipelines. Use python3 -c 'import csv...' for complex CSV parsing.
Ensure cut ranges passed in shell scripts are validated against unexpected input. Passing unchecked user variables directly into cut options could allow option injection or invalid range crashes.
GNU/Linux, BSD, and BusyBox Implementation Differences
POSIX cut standardizes -b, -c, -d, -f, and -s. However, the --complement and --output-delimiter options are GNU extensions and are not supported on standard BSD cut (macOS, FreeBSD) or BusyBox cut (Alpine Linux).
On BusyBox systems (Alpine Docker images), cut supports standard short flags (-d, -f, -c, -s). For portable cross-platform scripts, avoid --output-delimiter and use awk or tr when changing output delimiters.
Troubleshooting Common Errors and Diagnostics
cut: the delimiter must be a single character
Root Cause: More than one character was passed to -d (e.g. cut -d'::' or cut -d' - ' file). POSIX and GNU cut strictly require a single-byte character delimiter.
Resolution: Use awk for multi-character delimiters.
# cut fails on multi-character delimiter:
# cut -d'::' -f1 file.txt
# Correct with awk:
awk -F'::' '{print $1}' file.txt
Consecutive spaces causing empty fields in cut output
Root Cause: cut -d' ' treats each individual space as a separate delimiter. Multiple consecutive spaces create empty intermediary fields.
Resolution: Squeeze consecutive spaces with tr -s ' ' before piping to cut, or use awk.
# Fix multiple spaces before cut:
ps -eo pid,comm | tr -s ' ' | cut -d' ' -f2
cut: you must specify a list of bytes, characters, or fields
Root Cause: The cut command was executed without passing one of the mandatory selection modes: -b, -c, or -f.
Resolution: Supply -f, -c, or -b along with the desired column or character range.
cut -d: -f1 /etc/passwd
Alternatives, Related Commands, and Related Tutorials
- awk Command in Linux: Syntax, Text Patterns, and Field Processing — Practical syntax, flags, and examples for
awk. - tr Command in Linux: Translate, Delete, and Squeeze Characters — Practical syntax, flags, and examples for
tr. - tee Command in Linux: Split and Redirect Streams with Examples — Practical syntax, flags, and examples for
tee. - sort Command in Linux: Sort Lines of Text and Numerical Data — Practical syntax, flags, and examples for
sort. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/etc/passwd. The trailing hyphen instructs cut to include field 3 and all subsequent fields up to the end of the line.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides





Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!