← Back to list

The cut Command: A Linux Beginner's Complete Guide to Extracting Data Like a Pro

Imagine you have a file with thousands of lines. Each line has 10 columns of data. You only need column number 3.

Anas · 2026-03-04 03:08 · 6 claps · 2.7 min read
#linux #meduim #linux-shell-script #lpic-1 #system-administration
Open on Medium ↗
Wiki topics: 🔓 · Open Source 🥊 · Combat Sports

The cut Command: A Linux Beginner's Complete Guide to Extracting Data Like a Pro

The cut Command

The cut Command

Imagine you have a file with thousands of lines. Each line has 10 columns of data. You only need column number 3.

What do you do?

A beginner opens the file, reads it manually, and copies what they need. A Linux user types one command and gets the job done in milliseconds.

That command is cut.

What Exactly is cut?

cut is a command-line tool that extracts specific sections from each line of a file or input. It's fast, lightweight, and incredibly powerful when combined with other commands.

Think of it as scissors — but smarter. You tell it exactly where to cut, and it does it perfectly every time.

The 3 Core Flags You Must Know

**-d — The Delimiter**

A delimiter is the character that separates your data. In a CSV file, it’s a comma , In /etc/passwd, it's a colon : In a TSV file, it's a tab \t

**-f — The Field**

After defining your delimiter, you tell cut which column (field) you want. -f1 = first column -f2,4 = second AND fourth column -f1-3 = columns 1 through 3

**-c — The Character Position**

When your data has no delimiter, you extract by character position. -c1-5 = characters 1 to 5 from each line -c10 = only the 10th character

Real World Examples

Example 1 — Extract all usernames from your system:

Every Linux system stores users in /etc/passwd. Each line looks like this:

root:x:0:0:root:/root:/bin/bash

To extract only the usernames (first field):

cut -d':' -f1 /etc/passwd

Output:

root
daemon
bin
sys
anas

Example 2 — Working with CSV files:

You have a file employees.csv:

John,Developer,50000,New York
Sara,Designer,45000,London
Ahmed,SysAdmin,55000,Marrakesh

Extract only names and cities (columns 1 and 4):

bash

cut -d',' -f1,4 employees.csv

Output:

John,New York
Sara,London
Ahmed,Marrakesh

Example 3 - Extract by character position: You have a log file where the date is always the first 10 characters:

2024-03-04 ERROR: disk full
2024-03-05 INFO: backup done

Extract only the dates:

cut -c1-10 logfile.txt

Output:

2024-03-04
2024-03-05

The Most Common Beginner Mistake

Almost every beginner writes this:

cat file.txt | cut -d':' -f1

This works. But it’s what Linux veterans call “Useless Use of Cat” 😄

You’re running two commands when one is enough.

The correct and efficient way:

cut -d':' -f1 file.txt

Same result. Faster. Cleaner. More professional. ✅

Combining cut with Other Commands

This is where cut becomes truly powerful.

With grep — find and extract:

grep 'anas' /etc/passwd | cut -d':' -f1,6

Find the user “anas” then extract their username and home directory.

With sort — extract then sort:

cut -d',' -f2 employees.csv | sort

Extract the job titles and sort them alphabetically.

With ps — extract process info:

ps aux | tr -s ' ' | cut -d' ' -f1,11

Extract usernames and their running commands.

Quick Reference Card

GoalCommandExtract field by delimitercut -d':' -f1 fileExtract multiple fieldscut -d',' -f1,3 fileExtract field rangecut -d':' -f1-3 fileExtract by charactercut -c1-10 fileCombine with grepgrep 'text' file | cut -d':' -f1

Practice Challenge 🔥

Try these yourself in your terminal:

# Challenge 1
cut -d':' -f1,7 /etc/passwd

# Challenge 2
ps aux | tr -s ' ' | cut -d' ' -f1 | sort | uniq

# Challenge 3 - what does this do?
cut -d':' -f1-4 /etc/passwd | head -5

Drop your answers in the comments 👇

Final Thought

***cut*** is simple. But mastering simple tools is what separates a real Linux SysAdmin from someone who just knows commands.

Every expert was once a beginner who took the time to understand the basics deeply.

Start with cut. Go deep. Then move forward.

Follow me for daily Linux content — one command at a time. 🐧

Linux #SysAdmin #LinuxAdmin #OpenSource #LearningLinux #LPIC1 #DevOps #Medium


메타데이터
post_id
fffaeba39b8a
slug
the-cut-command-a-linux-beginners-complete-guide-to-extracting-data-like-a-pro-fffaeba39b8a
url
https://medium.com/@0x9z/the-cut-command-a-linux-beginners-complete-guide-to-extracting-data-like-a-pro-fffaeba39b8a
canonical_url
https://medium.com/@0x9z/the-cut-command-a-linux-beginners-complete-guide-to-extracting-data-like-a-pro-fffaeba39b8a
author_url
https://medium.com/@0x9z
status
ok
fetched_at
2026-07-13 06:23:13