🖥️printf
➡️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 printf command with important options and switches using examples.
6 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ██████╗ ██╗███╗ ██╗████████╗███████╗
# ██╔══██╗██╔══██╗██║████╗ ██║╚══██╔══╝██╔════╝
# ██████╔╝██████╔╝██║██╔██╗ ██║ ██║ █████╗
# ██╔═══╝ ██╔══██╗██║██║╚██╗██║ ██║ ██╔══╝
# ██║ ██║ ██║██║██║ ╚████║ ██║ ██║
# ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝
#==============================#
# CMD PRINTF
#==============================##==============================#
printf "%x\n" {1..65535} | while read -r u ; do printf "\033[38;5;$((16+$((16#$u))%230))m\u$u\033[0m"; done
# Make a Unicode rainbow
printf "\e[%dm%d dark\e[0m \e[%d;1m%d bold\e[0m\n" {30..37}{,,,}
#Show your basic terminal text colors for terminal preferences change.
printf "1800-01-13 +%s months\n" {0..4800} |date -f - |grep ^Fri |awk '{print $NF}' |uniq -c |grep " 3 "
# Show years with 3 Fri 13ths
printf "now +%s months\n" {0..240}| date -f - |grep ^Fri
# Find all Friday 13ths in the next 20 years.
printf ".\n.\n.\n.\n.\n.\na\na\nb\nb\nb\nc\nc\n" | sort -R
# Run multiple times and this will demonstrate how sort -R is different from shuf
printf "10^%d\n" {0..20} | bc | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
# Add separator commas to long numbers.
printf ".\n.\n.\n.\n.\n.\na\na\nb\nb\nb\nc\nc\n" | sort -R
# Run multiple times and this will demonstrate how sort -R is different from shuf
printf "2017-01-14 + %d weeks\n" {1..50} |date -f- +"%B %_d"
# Print the dates for all the following Saturdays in 2017 for use in a document
printf "%d\n" "')"
# Print the decimal encoded value of a ). The ' before the character tells printf to interpret the character this way.
printf "This is @climagic's %dth tweet. Thank you to my %d followers.\n\e[32m===,=='===\e[31m@\e[0m\n" $((10**4)) $((2**17))
printf "%d\n" "')"
# Print the decimal encoded value of a ). The ' before the character tells printf to interpret the character this way.
printf "%x\n" $(seq 0 255) | xargs -n1 -IH echo -ne \\xH > test.dat
# Generate binary sequence data
printf "Happy %dth Birthday %s\n" $((2**6)) "Richard Stallman" | figlet -w 64
# gibt was aus und macht dann figlet schrift draus
printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"
# Estimate an economic bitcoin-cli fee and display as sat/B with date time stamp -> Compactly display a bitcoin-cli fee estimate in satoshis/Byte, sat/B, date time stamp. Change the 6 to the desired number of confirmations. Display in btc/KB unit of measure: printf %g "$(bccli estimatesmartfee 6 "ECONOMICAL" | jq .feerate)";printf " btc/KB estimated feerate for 6 confirmations\nMultiply by 100,000 to get sat/B\n"; Two settings for estimate mode are "ECONOMICAL". "CONSERVATIVE" is the same as "UNSET"
# jq is a json filter. sudo apt-get install jq
# This is sample output - yours may be different.
163.808 sat/B estimated feerate for 6 confirmations as of Wed 20 Jun 2018 07:19:14 AM MDT
Divide by 100,000 to get btc/KB
# Estimate an economic bitcoin-cli fee and display as sat/B with date time stamp
# Compactly display a bitcoin-cli fee estimate in satoshis/Byte, sat/B, date time stamp. Change the 6 to the desired number of confirmations. Display in btc/KB unit of measure: printf %g "$(bccli estimatesmartfee 6 "ECONOMICAL" | jq .feerate)";printf " btc/KB estimated feerate for 6 confirmations\nMultiply by 100,000 to get sat/B\n"; Two settings for estimate mode are "ECONOMICAL". "CONSERVATIVE" is the same as "UNSET" # jq is a json filter. sudo apt-get install jq Show Sample Output
# 163.808 sat/B estimated feerate for 6 confirmations as of Wed 20 Jun 2018 07:19:14 AM MDT
# Divide by 100,000 to get btc/KB
printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"
printf "%s\n" T{Q,0}{Q,0}X{0,Q,B}{B,P,8}3569R7D9C5
# Print out all the combinations of a game card for which you accidentally scratched too hard. Ambiguous characters are expanded in sets using brace expansion {0,Q,B}, etc. I just had to do this and it worked.
printf "%080d" | tr 0 n
# Print the character 'n' 80 times. Useful for stuff like making lines for headers/breaks. Put it in a function.
# Print a horizontal line
# Replace the underscore with any other character. e.g. + or - or =
printf "%`tput cols`s"|sed "s/ /_/g"
# Print a horizontal line
printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${1--}}
# Make M-n, M-m, and M-, insert the zeroth, first, and second argument of the previous command in Bash
printf %s\\n '"\en": "\e0\e."' '"\em": "\e1\e."' '"\e,": "\e2\e."'>>~/.inputrc
# Check whether IPv6 is enabled Checks whether IPv6 is enabled system-wide by reading from procfs.
printf "IPv6 is "; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] && printf "enabled\n" || printf "disabled\n"
# Edit the Gimp launcher file to disable the splash screen
printf '%s\n' ',s/^Exec=[^ ]*/& -s/' w q | ed /usr/share/applications/gimp.desktop
# Explanation: sed is designed for editing streams - editing files is what ed is for! You can get consistent behavior on any UNIX platform with the above one-liner. The printf command sends a series of editing commands to ed, each separated by a newline. In this case, the substitution command ,s/^Exec=[^ ]*/& -s/ is nearly the same as in sed, appending a space and a -s to the line starting with Exec=. The only difference is the comma at the beginning designating the lines to operate on. This is shorthand for 1,$, which tells ed to apply the command to the first through the last lines (i.e., the entire file). w tells ed to write the file, and q to quit.
# Generate a sequence of numbers
printf '%s\n' {1..10}
# printf command can auto-escape strings...
_unclean_input='some th!ng n@$ty'
printf '%q\n' "${_unclean_input}"
#> some\ th\!ng\ n@\$ty
#==============================##==============================#
# CMD PRINTF
#==============================##==============================#
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 printf in a clear format. This allows users to quickly access the needed information for printf without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for printf 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.