Skip to main content

Linux command: cut

Illustration: Scissors | src: https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwjSzIjQlbjhAhWt-GEKHZMyCEMQjRx6BAgBEAU&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FFile%3AScissors_icon_black.svg

cut - remove sections from each line of files

$ which cut
/usr/bin/cut
$ cut --version
cut (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David M. Ihnat, David MacKenzie, and Jim Meyering.

Examples of cut

List all VMs in Qubes OS, then use cut to get the first column

Qubes OS: list all VMs

$ qvm-ls | cut -d " " f 1 # Number 1 NOT letter L
$ qvm-ls | cut -d" " f1  # or NO space in between options and value
Use cut to get the first column

Extract username and id from /etc/passwd file

Delimiter is ":", username is in column 1 and id is in column 3.

$ cut -d: -f1,3 /etc/passwd
Extract username and id from /etc/passwd file
'cut' selects columns, 'head' and 'tail' select rows

Popular posts from this blog

PHP: Notes

" PHP was originally an abbreviation of Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor. " — Wikipedia

Check and install php7.0-mbstring extention on Ubuntu 16.04 and Microsoft Windows

While learning Facebook SDK for PHP I overlooked one of system requirements preventing my code from running on my host. That is The mbstring extension. Facebook SDK for PHP's system requirements Check if mbstring is enabled root@ubuntu001:~# php -a Interactive mode enabled php > echo extension_loaded('mbstring'); php >exit root@ubuntu001:~# apt-cache search php7 | grep mbstring php7.0-mbstring - MBSTRING module for PHP root@ubuntu001:~# Install php7.0-mbstring root@ubuntu001:~# apt-get install php7.0-mbstring Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required:   fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0   libjpeg-turbo8 libjpeg8 libmcrypt4 libtiff5 libvpx3 libxpm4 Use 'apt autoremove' to remove them. The following additional packages will be installed:   libapache2-mod-php7.0 php7.0-cli ph...

Windows: Cleanup Installer folder

Let's cleanup orphaned files in %windir%\Installer folder to reclaim space from our expensive SSD.