🖥️cut
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the cut command with important options and switches using examples.
4 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗██╗ ██╗████████╗
# ██╔════╝██║ ██║╚══██╔══╝
# ██║ ██║ ██║ ██║
# ██║ ██║ ██║ ██║
# ╚██████╗╚██████╔╝ ██║
# ╚═════╝ ╚═════╝ ╚═╝
# cut - select columns of text from each line of a file
# if you're needing more comprehensive pattern-directed
# scanning and processing, take a look at `awk`
# Given a text file (file.txt) with the following text:
# unix or linux os
# is unix good os
# is linux good os
# cut will return the fourth element if given:
cut -c4 file.txt
x
u
l
# cut will return the fourth and sixth element if given:
cut -c4,6 file.txt
xo
ui
ln
# cut will return the fourth through seventh element if given:
cut -c4-7 file.txt
x or
unix
linu
# to use cut like `awk` you could do the following to return the
# second element, delimetered by a space:
cut -d' ' -f2 file.txt
or
unix
linux
# in the same way as above you can modify -f to return varying results:
cut -d' ' -f2,3 file.txt
or linux
unix good
linux good
# To cut out the third field of text or stdoutput that is delimited by a #:
cut -d# -f3
#==============================#
# CMD CUT
#==============================##==============================#
cut -c 1-$COLUMNS file
# trim output data width of file to the exact width of your terminal.
cut -d, -f1,5,10-15 data.csv > new.csv
# Use cut to print out columns 1, 5 and 10 through 15 in data.csv and write that to new.csv
cut -d: -f1-2 messages | uniq -c
# count hits per minute in your messages log file. Useful when you get "slammed" to do stats.
cut -c 1-80 file
# trim output data width of file to 80 characters per line.
# Find video files cached by the flash plugin in browsers
file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:
# Explanation: Recent versions of the flash plugin hide the temporary file by marking it deleted. Practically the video stream is downloaded to a "deleted file". However, even when a file is deleted, if the file is opened by a process then you can find its file descriptor and consequently the file contents.
# This simple script prints out the file descriptors of opened Flash videos:
file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:
# And, you probably want to create a regular file from the file descriptor, for example:
cp $(file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d: | head -n 1) video.avi
# Otherwise the file descriptor is not very convenient (remember, it's a deleted file!) The method should work regardless of your browser.
# In a list of files and folders with folders ending with /, count the number of folders below each 3-levels-deep subdirs. Helps determine where things are organized the most.
grep "/$" filefolderlist.txt | cut -d/ -f1-3 | sort | uniq -c
# I have needed to do this before. This fixes the file names:
length=5 # longest integer
for i in [0-9]*.png
do
number=$(printf "%0*d\n" $length $(echo $i|cut -f1 -d'.'))
suffix=$(echo $i|cut -f2 -d'.')
echo $number'.'$suffix " <- " $i
done|sort -n
# Make dotfile links
#!/bin/sh
MY_PATH='sdcard/repo/dotfiles/';
for file in ./sdcard/repo/dotfiles/;
do
MY_FILE=`echo $file | rev | cut -f1 -d'/' | rev` ;
echo "ln -s $MY_PATH$MY_FILE .$MY_FILE";
done
#==============================##==============================#
# CMD cut #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command cut in a clear format. This allows users to quickly access the needed information for cut without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for cut are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.