• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

cut Command Examples in Linux

by admin

The cut command extracts the specified lines of text from a file. Common cut command options and their uses are given in the following table.

Option Description
-c Specify the number of the character to cut from each line.
-d{delimiter} Separate one field from another.
-f{field numbers} Specify the field numbers to cut on as separated by the delimiter. For example, -f2 indicates the field between the first and second instances of the delimiter.
-s Suppress a line if the delimiter is not found.

Syntax

The syntax of the cut command is:

# cut [options] {file names}

The cut command is used to display only specific columns or characters from a text file or from other command outputs. For example, in the following command, we display the login names from the /etc/passwd file:

$ cut -d: -f1 /etc/passwd

cut Command Examples

1. Print a specific character/field range of each line:

# command | cut --characters|fields=1|1,10|1-10|1-|-10

2. Print a range of each line with a specific delimiter:

# command | cut --delimiter="," --characters=1

3. Print a range of each line of the specific file:

# cut --characters=1 path/to/file

4. The following command line displays the first and third fields from a colon-delimited file (extra lines stripped from output):

$ cut -d: -f1,3 /etc/passwd

5. The following command line display only the first four characters of every line in the /etc/passwd file:

$ cut -c 1-4 /etc/passwd

Filed Under: Linux

Some more articles you might also be interested in …

  1. caja Command Examples in Linux
  2. chrt : command not found
  3. mdp Command Examples
  4. git delete-branch: Delete local and remote Git branches
  5. gpasswd: command not found
  6. “git standup” Command Examples
  7. How to Change Password Of An LXC Container User Account
  8. “git check-attr” Command Examples
  9. setserial: command not found
  10. cpulimit Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright