FactorPad
Build a Better Process

Linux cut Command Summary with Examples

Linux cut allows you to select sections from lines of text.
  1. Purpose - Learn what cut is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with cut.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux cut, 33 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / cut-command.html


An ad-free and cookie-free website.


Examples of the Linux cut command

Beginner

Learn to select sections of text at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux cut Command Summary with Examples (3:51)

Video Script

The Command and Why You Need It

Our thirty-third word, or command to memorize is cut from our category Text.

cut allows you to select sections from lines of text.

Common Linux cut Options
-options description
-b, --bytes=LIST Select using bytes specified
-c, --characters=LIST Select using characters specified
-f, --fields=LIST Select using fields specified

Recall from the previous videos, we've been adding skills to help filter potentially huge files and cut is another tool for our arsenal.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The cut command has 10 options, and the argument is our file.

Like most commands, help is available with double-dash --help. The command has options for cutting bytes using -b, characters with -c, and we'll use that one here. And finally -f for fields.

A delimiter option is available too. If you've worked with spreadsheets then this concept is familiar.

So why is cut an important command? Well, we're often given data sets in columnar structure and, like in a spreadsheet, we need a way to pull out what is useful. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. I started with an ls -log command, for a list of files we've created up to this point, naming it video33.txt if you'd like to do the same on your end. And we can cat this to view.

$ cat video33.txt -rw-r--r-- 1 176 Oct 4 18:14 video05.txt -rw-r--r-- 1 100 Oct 10 18:42 video11.txt -rw-r--r-- 1 0 Oct 9 21:16 video16.txt -rw-r--r-- 1 45 Oct 12 10:11 video19.txt -rw-r--r-- 1 149 Oct 12 16:10 video20.txt -rw-r--r-- 1 31 Oct 13 10:11 video21.txt -> ../ridiculouslylongfilename.txt -rw-r--r-- 1 86 Oct 13 19:40 video23.txt -rw-r--r-- 1 86 Oct 15 13:17 video24.txt -rw-r--r-- 1 1203 Oct 15 20:05 video26.txt -rw-r--r-- 1 1259 Oct 15 21:17 video27.txt -rw-r--r-- 1 352 Oct 17 21:17 video31.txt -rw-r--r-- 1 362 Oct 18 12:26 video32.txt -rw-r--r-- 1 0 Oct 18 16:24 video33.txt

Next, let's cut a couple columns we're interested in, by using characters with cut -c 19-24, 32-42 and the argument is video33.txt.

$ cut -c 19-24,32-42 video33.txt Oct 4video05.txt Oct 10video11.txt Oct 9video16.txt Oct 12video19.txt Oct 12video20.txt Oct 13video21.txt Oct 13video23.txt Oct 15video24.txt Oct 15video26.txt Oct 15video27.txt Oct 17video31.txt Oct 18video32.txt Oct 18video33.txt $ clear

And last, because we'd like to add a delimiter between the fields, let's add the option --output-delimiter=":". Then we're good to go. And write that whole thing to a new file video34.txt, because we're not done with this data.

$ cut -c 19-24,32-42 --output-delimiter=":" video33.txt > video34.txt $ ls stuff video11.txt video19.txt video21.txt video24.txt video27.txt video32.txt video34.txt video05.txt video16.txt video20.txt video23.txt video26.txt video31.txt video33.txt

Then cat it if you'd like.

$ cat video34.txt Oct 4:video05.txt Oct 10:video11.txt Oct 9:video16.txt Oct 12:video19.txt Oct 12:video20.txt Oct 13:video21.txt Oct 13:video23.txt Oct 15:video24.txt Oct 15:video26.txt Oct 15:video27.txt Oct 17:video31.txt Oct 18:video32.txt Oct 18:video33.txt

A Final Tip

Okay now you know how to use cut. And you know the syntax for commands, options and arguments.

One last tip about the cut command. So we've all seen a cut command on a PC or a Mac, have you noticed how flexible this one is?

Okay, thanks for visiting today. I hope this was a helpful introduction to the cut command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Keep the learning train moving forward. Connect at YouTube, Twitter and at our no-spam email list to stay on track.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / cut-command.html


linux cut command
cut linux
linux cut examples
unix cut
cut unix
linux cut examples
linux cut tutorial
select text in linux
remove text in linux
cut command syntax
cut command summary
cut command options
cut command examples
cut man page
man cut linux
shell cut

A newly-updated free resource. Connect and refer a friend today.