Cut Command in Linux

In Linux and Unix systems, there are many utilities that you can use to process and filter text files. cut is a command-line utility that allows you to cut parts of a line from specified files or piped data and print the result to standard output. It can be used to cut parts of a line by delimiter, byte position, and character.
This article will show you how to use the cut command through practical examples and detailed explanations of the most common options.
How to Use the cut Command
The syntax for the cut command is as follows:
cut OPTION... [FILE]...The flags that instruct cut whether to use a delimiter, byte position, or character when cutting out selected portions of the lines are as follows:
-f(--fields=LIST) - Select by specifying a field, a set of fields, or a range of fields. This is the most commonly used option.-b(--bytes=LIST) - Select by specifying a byte, a set of bytes, or a range of bytes.-c(--characters=LIST) - Select by specifying a character, a set of characters, or a range of characters.
You can use one and only one of the flags listed above.
Other flags are:
-d(--delimiter) - Specify a delimiter that will be used instead of the default “TAB” delimiter.--complement- Complement the selection. When using this option,cutdisplays all bytes, characters, or fields except the selected ones.-s(--only-delimited) - By default,cutprints the lines that contain no delimiter character. When this option is used,cutdoes not print lines not containing delimiters.--output-delimiter- The default behavior ofcutis to use the input delimiter as the output delimiter. This option allows you to specify a different output delimiter string.
The cut command can accept zero or more input FILE names. If no FILE is specified, or when FILE is -, cut will read from the standard input.
The LIST argument passed to the -f, -b, and -c options can be an integer, multiple integers separated by commas, a range of integers or multiple integer ranges separated by commas. Each range can be one of the following:
N- The Nth field, byte, or character, starting from 1.N-- From the Nth field, byte, or character to the end of the line.N-M- From the Nth to the Mth field, byte, or character.-M- From the first to the Mth field, byte, or character.
How to Cut by Field
To specify the fields that should be cut, invoke the command with the -f option. When not set, the default delimiter is “TAB”.
In the examples below, we will use the following file. The fields are separated by tabs.
245:789 4567 M:4540 Admin 01:10:1980
535:763 4987 M:3476 Sales 11:04:1978For example, to display the 1st and the 3rd fields you would use:
cut -f 1,3 test.txt245:4540 Admin 01
535:3476 Sales 11Or if you want to display from the 1st to the 4th field:
cut -f -4 test.txt245:789 4567 M:4540 Admin
535:763 4987 M:3476 SalesHow to Cut Based on a Delimiter
To cut based on a delimiter, invoke the command with the -d option, followed by the delimiter you want to use.
For example, to display the 1st and 3rd fields using “:” as a delimiter, you would type:
cut -d ':' -f 1,3 test.txt245:789 M:4540
535:763 M:3476You can use any single character as a delimiter. In the following example, we are using the space character as a delimiter and printing the 2nd field:
echo "Lorem ipsum dolor sit amet" | cut -d ' ' -f 2ipsumHow to Complement the Selection
To complement the selection field list, use the --complement option. This will print only those fields that are not selected with the -f option.
The following command will print all fields except the 1st and 3rd:
cut test.txt -f 1,3 --complement4567 Admin 01:10:1980
4987 Sales 11:04:1978How to Specify an Output Delimiter
To specify the output delimiter, use the --output-delimiter option. For example, to set the output delimiter to _, you would use:
cut -f 1,3 --output-delimiter='_' test.txt245:789_M:4540
535:763_M:3476How to Cut by Bytes and Characters
Before going any further, let us make a distinction between bytes and characters.
One byte is 8 bits and can represent 256 different values. When the ASCII standard was established, it took into account all of the letters, numbers, and symbols necessary to work with English. The ASCII character table has 128 characters, and each one is represented by one byte. When computers became globally accessible, tech companies introduced new character encodings for different languages. For languages with more than 256 characters, a simple 1 to 1 mapping was not possible. This led to many problems, such as sharing documents or browsing websites, and a new Unicode standard that could handle most of the world’s writing systems was needed.
UTF-8 was created to solve these problems. In UTF-8, not all characters are represented with 1 byte. Characters can be represented with 1 byte to 4 bytes.
The -b (--bytes) option tells the command to cut sections from each line specified by given byte positions.
In the following examples, we are using the ü character that takes 2 bytes.
Select the 5th byte:
echo 'drüberspringen' | cut -b 5bSelect the 5th, 9th, and 13th bytes:
echo 'drüberspringen' | cut -b 5,9,13bpgSelect the range from 1st to 5th byte:
echo 'drüberspringen' | cut -b 1-5drübThe -b option cuts bytes, while -c cuts characters. On multibyte locales, -c counts characters, but results can differ depending on your locale settings.
Cut Examples
The cut command is usually used in combination with other commands through piping. Here are a few examples:
Get a list of all users
The output of the getent passwd command is passed to cut, which prints the 1st field using : as a delimiter.
getent passwd | cut -d ':' -f1The output shows a list of all system users .
Extract Values from Comma-Separated Data
You can use cut with a comma delimiter to extract fields from CSV-like text:
echo "name,role,shell" | cut -d ',' -f2roleFor real CSV files with quoted commas, use a CSV-aware tool instead of cut.
If you need to handle repeated spaces as a delimiter, normalize the input first with tr
or awk, then use cut on the cleaned data. For example:
echo "one two three" | tr -s ' ' | cut -d ' ' -f2twoPrint the Default Shell for the Current User
The following command reads the current user’s entry from /etc/passwd and extracts the 7th field, which holds the login shell:
grep "^$USER:" /etc/passwd | cut -d ':' -f7/bin/bashQuick Reference
| Option | Description |
|---|---|
-f LIST | Select fields (default delimiter: TAB) |
-b LIST | Select bytes |
-c LIST | Select characters |
-d DELIM | Use DELIM as the field delimiter |
--complement | Invert the selection |
-s | Skip lines that contain no delimiter |
--output-delimiter=STR | Use STR as the output delimiter |
LIST can be a single number (2), a comma-separated set (1,3), or a range (2-5). Use N- to select from position N to the end of the line.
Conclusion
cut is a fast, lightweight tool for extracting structured fields from text files and pipeline output. For cases where cut falls short, such as multiple delimiters or pattern-based extraction, awk
is the natural next step.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page