Website Vidya
Cloud & DevOpsStep-by-Step Guide

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.

RR
Rajesh RayLead Systems Educator
Published:
9 min read
PDF Cheat Sheet
Cut Command in Linux: Extract Columns, Fields, and Characters
AI Executive SummaryWebsiteVidya AI

9 min read

Learn cut command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

Key Highlights
  • What cut Does and When to Use It
  • Availability and Installation Across Linux Distributions
  • Command Syntax, Arguments, and Exit Status Codes
Grounded in full engineering runbookWebsiteVidya AI Engine

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.

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.

Advertisement
Cut Command in Linux: Extract Columns, Fields, and Characters — syntax, flags, and practical terminal workflow diagram
Cut Command in Linux: Extract Columns, Fields, and Characters — command syntax, key options, and production workflow reference.

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:

Advertisement

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 / FlagLong Form / ArgumentTechnical Behavior and Purpose
-d DELIM--delimiter=DELIMUse DELIM instead of TAB for field delimiter (must be a single character).
-f LIST--fields=LISTSelect only these fields; also print any line that contains no delimiter character unless -s.
-c LIST--characters=LISTSelect only these characters (ranges like 1-5, 8, 12-).
-b LIST--bytes=LISTSelect only these bytes (ignores multibyte boundaries).
-s--only-delimitedDo not print lines that do not contain delimiter characters.
--complement--complementInvert the selection: output all fields, bytes, or characters EXCEPT the selected ones.
--output-delimiter=STRING--output-delimiter=STRINGUse STRING as the output field delimiter instead of the input delimiter.
--help--helpDisplay 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.

Advertisement

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 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

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
No. Standard cut always outputs fields in the order they appear in the original input, regardless of how you specify them in -f (e.g. cut -f3,1 still prints field 1 before field 3). To reorder columns, use awk: awk '{print $3, $1}'.
-b slices by raw byte offsets, which can corrupt multibyte UTF-8 characters. -c slices by character counts, correctly preserving multibyte characters in modern UTF-8 locales.
Use an open-ended range: cut -d: -f3- /etc/passwd. The trailing hyphen instructs cut to include field 3 and all subsequent fields up to the end of the line.
By default, POSIX cut prints lines lacking the delimiter unchanged. To suppress lines that do not contain the delimiter, pass the -s (--only-delimited) flag.
RR
Written byVerified Author

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.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Cloud & DevOps•

How to Close File Descriptors Above 9 in Dash Shell

Attempting to close a file descriptor above 9 in Dash using exec 10<&- results in a 10: not found error because Dash's POSIX lexer only recognizes single-digit file descriptors (0–9) in redirection operators. This guide explains the exact parser limitation, why FDs 10+ are reserved for internal shell state, and how to safely close inherited file descriptors using close_range, Python, or Perl wrappers.

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout