🖥️echo
➡️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 echo command with important options and switches using examples.
15 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ███████╗ ██████╗██╗ ██╗ ██████╗
# ██╔════╝██╔════╝██║ ██║██╔═══██╗
# █████╗ ██║ ███████║██║ ██║
# ██╔══╝ ██║ ██╔══██║██║ ██║
# ███████╗╚██████╗██║ ██║╚██████╔╝
# ╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝
#==============================#
# CMD ECHO
#==============================##==============================#
echo "php-faq [dot] eu is the world's best website for qualitative Linux article" | pv -qL 20
# You might have seen simulating text in Movies specially Hollywood Movies, where the text appears as if it is being typed in the Real time. You can echo any kind of text and output in simulating fashion using ‘pv‘ command, as pipelined above.
echo yoυrbank.com | hexdump -c
# Check a domain to make sure its all the ASCII characters you expect and not Unicode look-a-likes
echo "$URL" | tr -s / _
# Change URL into a more filesystem friendly form and squeeze the repeated _ chars into one. #TryingAgain
echo ".05*37652825" | bc
# Calculate how much money I would have if I had a nickel for every potentially hacked wordpress based site.
echo "AabBcc" | sed s/[ab]//ig |\ > awk '{print "g"$1, "-v"}' | sh
echo "DISPLAY=$DISPLAY xmessage call the client" | at 10:00
# Verschiedene Befehle die dann zu einem bestimmten Zeitpunkt ausgeführt werden
echo "Listen to which album?" ; se lect album in */ ; do mplayer "$album"/* ; done
# Poor folks multi music album player.
echo "Only $((16#F)) days left until $((16#7E0))"
# Convert hex to dec on the fly.
echo "Tacos,Burgers,Pizza,Pasta,Sushi,Salad,Soup,Noodles,Veggie wraps" | tr ',' '\n' | sort -R | head -1
# Simple lunch location decider.
echo "Tacos,Burgers,Pizza,Sushi,Salad,Noodles,Veggie wraps" | awk -F, '{print $1}'
# Simple lunch location decider.
echo "fuzzbuzz" | sed -e "s/u/i/2"
# Replace the second occurrence of a regex match.
echo "ibase=10;obase=12;2016" | bc
# In the #dozenal system, we've entered a new dozenal century (biquennium).
echo "ls -l" | at midnight
at midnight<<<<'ls -l'
echo "obase=16;ibase=10;40" | bc
# You can use the bc command to convert base 10 numbers to base 16 (hexadecimal). Tip: Specify obase first.
echo "scale=1000;4*a(1)*2" | BC_LINE_LENGTH=1004 bc -l | cut -c1-629
# Happy Tau (τ) day!
echo $(( ( $( date +%s ) - $( date -d "now - 7 years" +%s ) ) /86400 ))
# Calculate 7 years ago in days, accounting for leap years. #GNU
echo $(( ( $( date +%s ) - $( date -d -v-7y +%s ) ) /86400 ))
# Calculate 7 years ago in days, accounting for leap years. #BSD
echo $((0x28))
# Convert hexadecimal number 28 to decimal 40. Can also do
echo $((16#28)) for the conversion.
echo $PATH | tr ':' '\ n'
# Human-readable path:
echo ${DISPLAY: -1}
# If you ever want to use a negative offset (from the end) for variable substrings, the space before the - is important.
echo ${USER:0:${#USER}/2}
# You can use arithmetic inside bash variable expansions, such as this to get the first half of your username
echo 'man $(ls /usr/bin | shuf -n 1)| sed -n "/^NAME/ { n;p;q }"' >> ~/.bashrc
# Learn a command on each new shell open.
echo addr show|ip -o -b -|cut -d' ' -f2,7
# Show IPv4 and IPv6 addresses per interface in Linux. Thx to all in #climagic on Freenode.
echo epoch day $(( $( date +%s ) / 86400 ))
# Sorry I missed this one by 2 days. Too damn busy.
echo test | rev | cut -c 2- | rev
# Use rev twice to get around limitation of cut not being able to truncate end of a string.
echo {1..9} | tr -d " " > /dev/udp/lights.climagic.com/45444
# Send 123456789 in a udp packet to the lights at http://lights.climagic.com
echo {a..z} ;
echo {n..z} {a..m}
# Make a quick rot13 translation quick reference table.
echo ".05*37652825" | bc
# Calculate how much money I'd have if I had a nickel for every potentially hacked wordpress based site.
echo epoch day $(( $( date +%s ) / 86400 ))
# Sorry I missed this one by 2 days. Too damn busy.
echo "ls -l > /dev/pts/0" | at 2:12 PM
# The ‘at‘ command is similar to cron command and can be used for scheduling a task or command to run at specified time. > : redirects the output
echo -e "You are a jerk\b\b\b\bwonderful person" | pv -qL $[10+(-2 + RANDOM%5)]
# Simulate typing but with mistakes The output will show jerk, then wonderful person since echo parses the \b character.
echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
# Simulate typing
echo "You can have a bit more realistic typing with some shell magic." | pv -qL $[10+(-2 + RANDOM%5)]
# Simulate typing
echo "pretty realistic virtual typing" | randtype -m 4
# Simulate typing this also generates errors (change 4 to higher number for more mistakes)
echo dir_1 dir_2 dir_3 | xargs -n 1 cp file1
# How to Copy A File to Multiple Directories in Linux With a Single Command
# -n 1 option on the xargs command tells it to only append one of those arguments at a time to the cp command each time it’s run.
echo dir_1 dir_2 dir_3 | xargs -n 1 cp copythisfile.txt
echo /home/user/1/ /home/user/2/ /home/user/3/ | xargs -n 1 cp /home/user/my_file.txt
echo -e '#!/bin/bash\necho My cksum is 918329835' > magic
# File containing its own checksum
# Quickly knock a UDP port in Linux
echo "ping" >/dev/udp/$host/$port
echo 'hello world' | sed s/world/orb/
# One way to practice sed commands is to pipe echo out.
echo %42%65%20%63%61%72%65%66%75%6c%20%77%68%61%74%2f%68%6f%77%20%79%6f%75%20%64%65%63%6f%64%65%0a | xxd -p -r
# Decode a hex encoded string
echo %42%65%20%63%61%72%65%66%75%6c%20%77%68%61%74%2f%68%6f%77%20%79%6f%75%20
echo $((2#1101))
# calculate binary 1101 → decimal printf '%x\n' $((2#1101)) # … → hexadecimal
echo -e "showconfig\ny" | ssh [email protected] | sed -n "/\?xml/,/\/config/p"
echo "set completion-ignore-case On" >> ~/.inputrc
# Case-insensitive tab completion - Pressing tab was never so easy with this linux input tweak
echo "some text `date +%Y-%m-%d\_%H:%M:%S`" >> /path/to/filename
# Add some text and the current date and time to a file -> This will output (without the quotes) "some text 2018-07-27_00:30:33" to /path/to/filename
echo -e "\$ORIGIN\tumccr.org.\n\$TTL\t1h\n" && aws route53 list-resource-record-sets --hosted-zone-id Z1EEXAMPLE9SF3 | jq -r '.ResourceRecordSets[] | [.Name, .Type, .ResourceRecords[0].Value] | join("\t")' - | grep -vE "NS|SOA"
# AWS Route53 hosted zone export -> Frustrated with the manual domain migration process AWS has, I unsuccessfully tried to install cli53, route53-transfer. I instead wrote this oneliner to ease the export (which is not supported via the AWS console ATM). The output can be easily pasted into the "Import Hosted Zone" dialog in Route53. SOA/NS records are excluded since they cannot be automatically imported. This is sample output - yours may be different.
$ORIGIN umccr.org.
$TTL 1h
umccr.org. MX 10 inbound-smtp.eu-west-1.amazonaws.com
umccr.org. TXT "google-site-verification=foo"
(...)
echo $(( $(grep -c '^ $' file_name) / 2 ))
# Count all [space][new line][space][new line] pattern using grep Using to count all sentences in CoNLL data format
echo "function backup() { local CA=c T=${TMPDIR:+/tmp}/backup.tar.gz; [[ -f $T ]]&& C=r; find ~ -type f -newer $T | tar ${CA}vfz $T -T - ;}" >> ~/.bashrc
# Make .bashrc function to backup the data you changed last houres -> The original overwrites any previous backups, and only saves exactly the last hours worth, but not 1 hour + 1 minute. This version creates or appends files, and backs up everything since the last backup (using the backups timestamp as the reference), plus it uses TMPDIR if set.
echo "New first line" | cat - file.txt > newfile.txt; mv newfile.txt file.txt
# Insert a line at the top of a text file without sed or awk or bash loops
# Just use '-' to use STDIN as an additional input to 'cat'
echo "$(find ./ -name '*' -type f -exec wc -l {} \; | awk '{print $1}' | tr '\n' '+' | sed s/+$//g)" | bc -l
# Count lines of the founded files
echo {a..z} ; echo {n..z} {a..m}
# Make a quick rot13 translation quick reference table.
echo 'mail -s "notify" [email protected] <<<"Buy flowers"' | at 3pm Feb 14
# Send flower reminder to your Verizon serviced phone.
echo "I want to cut off the end of this sentence. Because reasons." | rev | cut -c 18- | rev
# Use rev twice to get around limitation of cut not being able to truncate end of a string.
echo 'Hello, my username is imontoya, you kill -9 my $PPID, prepare to vi.'
#
echo $((0x2F))
# Convert hexadecimal number 2F to decimal 47. Can also do echo $((16#2F)) for the conversion.
echo 'man $(ls /usr/bin | shuf -n 1)| sed -n "/^NAME/ { n;p;q }"' >> ~/.bashrc
# Learn a command on each new shell open.
# Generate a sequence of numbers.
echo {1..99}
# Create a sequence of integer numbers
echo {4..-9}
# Explanation:
# Useful for counters. For example, to do something 10 times, you could do for i in {1..10}; do something; done
# Be careful, there cannot be spaces between the braces
# As the example shows, can count backwards too
# Limitations: Does not work in /bin/sh, this is bash specific.
# Produce 10 copies of the same string
echo boo{,,,,,,,,,,}
# Generate a sequence of numbers.
# Uses bash shortcut to generate series, it works with letters too echo {A..H} echo {a..h} Be careful not to mix upper and lower case, you may encounter funny results : echo {z..A} z y x w v u t s r q p o n m l k j i h g f e d c b a ` _ ^ ] [ Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
echo {1..12}
# Sample outpt:
1 2 3 4 5 6 7 8 9 10 11 12
# Test sendmail
# test if sendmail is installed and working.
echo "Subject: test" | /usr/lib/sendmail -v [email protected]
# Sample outpt:
[root@machine]# echo "Subject: test" | /usr/lib/sendmail -v [email protected]
[email protected]... Connecting to [127.0.0.1] via relay...
[email protected]... Deferred: Connection refused by [127.0.0.1]
# OSX script to change Terminal profiles based on machine name; use with case statement parameter matching
# /macos/mojave shell script to change terminal profiles
echo "tell application \"Terminal\"\n\t set its current settings of selected tab of window 1 to settings set \"$PROFILE\"\n end tell"|osascript;
# Check SSL expiry from commandline
echo | openssl s_client -showcerts -servername google.com -connect gnupg.org:443 2>/dev/null | openssl x509 -inform pem -noout -text
# Halt the system in Linux without the halt command or gui
echo o > /proc/sysrq-trigger
# Explanation:
# First you need to enable the sysrq interface with: echo 1 > /proc/sys/kernel/sysrq
# echo o > /proc/sysrq-trigger halts
# echo b > /proc/sysrq-trigger reboots
# Uses 'at' to run an arbitrary command at a specified time.
echo 'play alarmclock.wav 2>/dev/null' | at 07:30 tomorrow
# Explanation: at 07:30 tomorrow schedules a job for 7:30 AM the next day, running whatever command or script is fed to it as standard input. The format for specifying time and date is rather flexible. http://tinyurl.com/ibmdwat
# echo 'play alarmclock.wav 2>/dev/null' | feeds the play alarmclock.wav command to at, while 2>/dev/null causes the text output of play to be thrown away (we are only interested in the alarm sound).
# Append to a file text, a blank line, and the last line of another file
echo -e "From: me\n\n$(tail -n1 /var/log/apache2/error.log)" >> file
# Explanation:
# -e option to echo makes it interpret '\n' as a newline
# $(command) syntax runs a command, then uses its output in place
# Limitations: The -e flag of echo does not work on all systems. In that case you can use printf instead.
## Alternative one-liners:
# Append to a file text, a blank line, and the last line of another file
{ echo some text; echo; tail -n1 /var/log/apache2/error.log; } >> /path/to/file
# Explanation: All the standard output from all the commands between the braces will be redirected.
# Redirect stdout to a file you do not have write permission on
echo hello | sudo tee -a /path/to/file
# Explanation:
# The tee command copies standard input to standard output, making a copy in zero or more files.
# If the -a flag is specified it appends instead of overwriting.
# Calling tee with sudo makes it possible to write to files the current user has no permission to but root does.
# Replace sequences of the same characters with a single character
echo heeeeeeelllo | sed 's/\(.\)\1\+/\1/g'
# Explanation: That is, this will output "helo".
# The interesting thing here is the regular expression in the s/// command of sed:
# \(.\) -- capture any character
# \1 -- refers to the last captured string, in our case the previous character. So effectively, \(.\)\1 matches pairs of the same character, for example aa, bb, ??, and so on.
# \+ -- match one or more of the pattern right before it
# ... and we replace what we matched with \1, the last captured string, which is the first letter in a sequence like aaaa, or bbbbbbb, or cc.
# Convert text from decimal to little endian hexadecimal
echo $(printf %08X 256 | grep -o .. | tac | tr -d '\n')
# Explanation:
# example of 256
# printf %08X produces the 8 characters 00000100
# grep breaks string by two characters
# tac reverses
# tr 00010000
# Run a command and copy its output to clipboard (Mac OSX)
echo "Here comes the output of my failing code" | tee >(pbcopy)
# Explanation:
# Often you need to copy the output of a program for debugging purposes. Cool kids on the block may use pastebin servers. But what if you'd just like to copy-and-paste the output to a web form, say? This one-liner gives a nice demonstration of process substitution. The stdout is piped to tee for duplication. Rather than dumping the output to a file as in the normal case, the output is piped to pbcopy via a temporary file that the OS conjures up on the fly (/dev/fd/XXX). The end result: you can paste the output wherever you want with Command+V.
# Limitations: This is Mac OSX specific. Use xsel on Linux.
# Blackhole ru zone
echo "address=/ru/0.0.0.0" | sudo tee /etc/NetworkManager/dnsmasq.d/dnsmasq-ru-blackhole.conf && sudo systemctl restart network-manager
# Explanation: It creates dnsmasq-ru-blackhole.conf file with one line to route all domains of ru zone to 0.0.0.0. You might use "address=/home.lab/127.0.0.1" to point allpossiblesubdomains.home.lab to your localhost or some other IP in a cloud.
# Dump all AWS IAM users/roles to a Terraform file for editing / reusing in another environment
echo iamg iamgm iamgp iamip iamp iampa iamr iamrp iamu iamup | AWS_PROFILE=myprofile xargs -n1 terraforming
# Explanation: Amazon Web Services (AWS) use a collection "IAM" resources to create Users and related objects in the system. This oneliner scrapes all the relevant info and puts it into Terraform. This lets us audit our users-groups. And, it lets us re-use them in another environment!
echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq"|dc
# Instead of saying RTFM!
echo -e ${PATH//:/\\n}
# "Pretty print" $PATH, show directories in $PATH, one per line with replacement pattern using shell parameter expansion
# Can be used to create path alias. From: https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html. #9
# Make a butterfly, or two people staring at each other, or that bridge in Adventure.
echo }{
# Send a random number to change the corresponding light on http://lights.climagic.org
echo $[RANDOM%9+1] > /dev/udp/lights.climagic.org/45444
# --version-sort = natural sort of (version) numbers within text
echo -e "1.png\n2.png\n3.png\n4.png\n5.png\n6.png\n7.png\n8.png\n9.png\n10.png\n11.png" | sort -V
# Get top level of path
echo '/'`pwd | cut -d'/' -f2`
echo doing something very nice!
echo 'doing something very evil' >/dev/null && echo doing something very nice!
# Sample output
# doing something very nice!
# Outputs list of $PATH dirs sorted by line length
echo -e ${PATH//:/\\n} | awk '{print length, $0}' | sort -n | cut -f2- -d' '
# Check if port is open on remote machine Check if port is open, if you don't have ncat on your machine.
echo > /dev/tcp/127.0.0.123/8085 && echo "Port is open"
# Sample output
# Port is open
# Hiding ur evil intent! Shame on you! - as a shell script, the possibilities are endless... #!/bin/bash echo doing something very evil! exit
# shell bash iterate number range with for loop
rangeBegin=10; rangeEnd=20; for ((numbers=rangeBegin; numbers<=rangeEnd; numbers++)); do echo $numbers; done
# shell bash iterate number range with for loop -> iterating range of numer with for loop in shell or bash
rangeBegin=10; rangeEnd=20; for numbers in $(eval echo "{$rangeBegin..$rangeEnd}"); do echo $numbers;done
# Sample output
# 10
# 11
# 12
# 13
# 14
# 15
# 16
# 17
# 18
# 19
# 20
# Fetter Text in der Konsole
# Manchmal möchte man etwas fett in der Konsole darstellen. Der einfachste weg führt dabei über Escape Sequenzen innerhalb von echo:
echo -e '\033[1mTEXT\033[0m'
# echo -e Die Option -e bedeutet, dass die Escape Sequenzen interpretiert werden
# \033 Signal für den Anfang der Formatierung
# kleines m Ende der Formatierung
# 1 Nummer für fett (andere Varianten siehe unten)
# [0m Zurücksetzen der Formatierung für alle nachfolgenden Elemente
# Formatierungsoptionen
# 0 Normale Formatierung
# 1 Fett
# 2 Kursiv
# 4 Unterstrichen
# 5 Blinkend
# 7 Rückwärts
# 8 Unsichtbar
# bash Montag Morgen beginnt mit einem 6er Pasch . \o/
echo $(</dev/urandom tr -dc 1-6 | head -c2)
66
#==============================##==============================#
# CMD ECHO
#==============================##==============================#
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 echo in a clear format. This allows users to quickly access the needed information for echo without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for echo 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.