Home > Articles

  • Print
  • + Share This
This chapter is from the book

cut

The cut command is used to display “sections” of data. Important options include the following:

Option Description
-b Used to define a section to print by bytes.
-c Used to define a section to print by characters.
-d Used to specify a delimiter character (used with the -f option).
-f Used to specify which fields to display.

Example using fields:

[student@localhost ~]$ head -2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[student@localhost ~]$ head -2 /etc/passwd | cut -d: -f1,7
root:/bin/bash
bin:/sbin/nologin

Example using characters:

[student@localhost ~]$ ls -l /etc/passwd
-rw-r--r--. 1 root root 2607 Nov 3 10:15 /etc/passwd
[student@localhost ~]$ ls -l /etc/passwd | cut -c1-10,42-
-rw-r--r-- /etc/passwd
  • + Share This
  • 🔖 Save To Your Account