Commands using echo (1,469)

  • This is an alternative to cron which allows a one-off task to be scheduled for a certain time.

    echo "ls -l" | at midnight
    root · 2009-01-25 21:07:42 13
  • This will output the characters at 10 per second.

    echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
    dennisw · 2010-01-14 20:17:44 7
  • Sometimes commands are long, but useful, so it's helpful to be able to make them permanent without having to retype them. An alternative could use the history command, and a cut/sed line that works on your platform. history -1 | cut -c 7- >

    echo "!!" >
    dnavarre · 2009-02-25 00:37:25 5
  • This is a simple example of using proper command nesting using $() over ``. There are a number of advantages of $() over backticks. First, they can be easily nested without escapes: program1 $(program2 $(program3 $(program4))) versus program1 `program2 \`program3 \`program4\`\`` Second, they're easier to read, then trying to decipher the difference between the backtick and the singlequote: `'. The only drawback $() suffers from is lack of total portability. If your script must be portable to the archaic Bourne shell, or old versions of the C-shell or Korn shell, then backticks are appropriate, otherwise, we should all get into the habit of $(). Your future script maintainers will thank you for producing cleaner code.

    echo "The date is: $(date +%D)"
    atoponce · 2009-03-07 15:51:59 8
  • defines a handy function for quick calculations from cli. once defined: ? 10*2+3 Show Sample Output

    ? () { echo "$*" | bc -l; }
    fizz · 2009-06-28 20:15:30 14
  • This is the result of a several week venture without X. I found myself totally happy without X (and by extension without flash) and was able to do just about anything but watch YouTube videos... so this a the solution I came up with for that. I am sure this can be done better but this does indeed work... and tends to work far better than YouTube's ghetto proprietary flash player ;-) Replace $i with any YouTube ID you want and this will scrape the site for the _real_ URL to the full quality .FLV file on Youtube's server and will then will hand that over to mplayer (or vlc or whatever you want) to be streamed. In some browsers you can replace $i with just a % or put this in a shell script so all YouTube IDs can be handed directly off to your media player of choice for true streaming without the need for Flash or a downloader like clive. (I do however fully recommend clive if you wish to archive videos instead of streaming them) If any interest is shown I would be more than happy to provide similar commands for other sites. Most streaming flash players use similar logic to YouTube. Edit: 05/03/2011 - Updated line to work with current YouTube. It could be a lot prettier but I will probably follow up with another update when I figure out how to get rid of that pesky Grep. Sed should take that syntax... but it doesn't. Original (no longer working) command: mplayer -fs $(echo "$(curl -s $youtube_url | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p")") Show Sample Output

    i="8uyxVmdaJ-w";mplayer -fs $(curl -s "$i" | echo -e $(sed 's/%/\\x/g;s/.*\(v[0-9]\.lscache.*\)/http:\/\/\1/g') | grep -oP '^[^|,]*')
    lrvick · 2009-03-09 03:57:44 15
  • Same as, but for bash. This will show a numerical value for each of the 256 colors in bash. Everything in the command is a bash builtin, so it should run on any platform where bash is installed. Prints one color per line. If someone is interested in formatting the output, paste the alternative.

    for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
    scribe · 2010-06-19 02:14:42 4
  • Good for one off jobs that you want to run at a quiet time. The default threshold is a load average of 0.8 but this can be set using atrun. Show Sample Output

    echo "rm -rf /unwanted-but-large/folder" | batch
    root · 2009-02-04 19:07:52 3
  • Tee can be used to split a pipe into multiple streams for one or more process to work it. You can add more " >()" for even more fun. Show Sample Output

    echo "tee can split a pipe in two"|tee >(rev) >(tr ' ' '_')
    axelabs · 2010-08-14 20:38:59 3
  • remotely connects to an https site, fetches the ssl certificate and displays the valid dates for the cert

    echo | openssl s_client -connect 2>/dev/null |openssl x509 -dates -noout
    systemj · 2009-02-05 15:21:50 3
  • You have an external USB drive or key. Apply this command (using the file path of anything on your device) and it will simulate the unplug of this device. If you just want the port, just type : echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") Show Sample Output

    echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") | sudo tee /sys/bus/usb/drivers/usb/unbind
    tweet78 · 2014-04-06 12:06:29 9
  • If X is 5, it will about a number between 1 and 5 inclusive. This works in bash and zsh. If you want between 0 and 4, remove the +1.

    echo $[RANDOM%X+1]
    goodevilgenius · 2010-08-07 02:43:46 5
  • Even faster without the need for cut... :)

    echo ${SSH_CLIENT%% *}
    bashrc · 2011-01-11 10:58:35 2
  • You got some results in two variables within your shell script and would like to find the differences? Changes in process lists, reworked file contents, ... . No need to write to temporary files. You can use all the diff parameters you'll need. Maybe anything like $ grep "^>" is helpful afterwards.

    diff <(echo "$a") <(echo "$b")
    olorin · 2009-07-15 07:26:23 2
  • Run the alias command, then issue ps aux | head and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand. ${LINES:-`tput lines 2>/dev/null||echo -n 12`} Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the deafault of 12 (-2 = 10). The default for HEAD is to output the first 10 lines, this alias changes the default to output the first x lines instead, where x is the number of lines currently displayed on your terminal - 2. The -2 is there so that the top line displayed is the command you ran that used HEAD, ie the prompt. Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( ) 275MB/748MB [7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~ In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device. Show Sample Output

    alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'
    AskApache · 2010-04-08 22:37:06 7
  • this command will send a message to the socket 25 on host in tcp. works on udp and icmp understand only IP address, not hostname. on the other side (, you can listen to this socket and test if you receive the message. easy to diagnose a firewall problem or not.

    echo "foo" > /dev/tcp/
    mobidyc · 2009-09-12 16:48:05 3
  • Why remember? Generate! Up to 48 chars, works on any unix-like system (NB: BSD use md5 instead of md5sum) Show Sample Output

    read -s pass; echo $pass | md5sum | base64 | cut -c -16
    bugmenot · 2011-11-24 20:23:47 9
  • This will perform one of two blocks of code, depending on the condition of the first. Essentially is a bash terniary operator. To tell if a machine is up: ping -c1 machine { echo succes;} || { echo failed; } Because of the bash { } block operators, you can have multiple commands ping -c1 machine && { echo success; }|| { echo failed;; } Tips: Remember, the { } operators are treated by bash as a reserved word: as such, they need a space on either side. If you have a command that can fail at the end of the true block, consider ending said block with 'false' to prevent accidental execution Show Sample Output

    true && { echo success;} || { echo failed; }
    clockworkavian · 2009-04-02 01:49:25 1
  • This command creates and burns a gapless audio CD with 99 tracks. Each track is a 30 second sine wave, the first is 1 Hz, the second 2 Hz, and so on, up to 99 Hz. This is useful for testing audio systems (how low can your bass go?) and for creating the constant vibrations needed to make non-Newtonian fluids (like cornstarch and water) crawl around. Note, this temporarily creates 500MB of .cdda files in the current directory. If you don't use the "rm" at the end of the command, you can burn more disks using cdrdao write cdrdao.toc Prerequisites: a blank CD-R in /dev/cdrw, sox (, and cdrdao ( I'm also assuming a recent version of bash for the brace expansion (which just looks nicer than using seq(1), but isn't necessary). Show Sample Output

    (echo CD_DA; for f in {01..99}; do echo "$f Hz">&2; sox -nt cdda -r44100 -c2 $f.cdda synth 30 sine $f; echo TRACK AUDIO; echo FILE \"$f.cdda\" 0; done) > cdrdao.toc && cdrdao write cdrdao.toc && rm ??.cdda cdrdao.toc
    hackerb9 · 2009-11-17 06:23:42 3
  • Useful when you've produced a large file of numbers, and want to quickly see the distribution. The value of y halfway along the x axis is the median. Simple! Just create the listOfNumbers.txt file with a number on each line to try it out.

    gnuplot -persist <(echo "plot '<(sort -n listOfNumbers.txt)' with lines")
    penthief · 2009-05-02 13:46:02 3
  • I like the fact the Patola's version uses only ones and zeros, but I also like the sparse output of the other versions. This one combines both of those features and eliminates some unnecessary cruft. You can vary the sparseness by changing "$(($RANDOM % 5))" to another number. The number in this term "$(($RANDOM % 4))" controls how frequently the numbers are output bold.

    echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done
    dennisw · 2009-09-27 15:30:38 2

  • 22
    echo "GRUB_INIT_TUNE=\"1000 334 1 334 1 0 1 334 1 0 1 261 1 334 1 0 1 392 2 0 4 196 2\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
    stanix · 2011-04-12 12:47:04 14

  • 22
    tail -f file | while read; do echo "$(date +%T.%N) $REPLY"; done
    yoyoyojomo · 2012-02-18 17:22:53 3
  • you know the song... sing along Show Sample Output

    echo {1..199}" bottles of beer on the wall, cold bottle of beer, take one down, pass it around, one less bottle of beer on the wall,, " | espeak -v english -s 140
    op4 · 2010-02-04 04:38:52 11
  • Easily convert numbers to their representations in different bases. Passing "ibase=16; obase=8; F2A" to bc will convert F2A (3882 in decimal) from Hex to Octal, and so on. Show Sample Output

    echo "obase=2; 27" | bc -l
    polar · 2009-03-25 09:54:50 2
  •  1 2 3 >  Last ›

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

check open ports without netstat or lsof

Rapidly invoke an editor to write a long, complex, or tricky command
Next time you are using your shell, try typing $ ctrl-x ctrl-e # in emacs mode or $ v # in vi mode The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.

List subfolders from largest to smallest with sizes in human readable form

Optimize Xsane PDFs
Xsane produces PDFs that are too large - particularly multipage PDFs. This command compresses them. If you do not use A4, remove the -sPAPERSIZE flag.

Copy a file and force owner/group/mode
This is useful when you want to copy a file and also force a user, a group and a mode for that file. Note: if you want to move that file instead of copying it, you can use $install -o user -g group -m 755 /path/to/file /path/to/dir/ && rm -f /path/to/file which will remove the file only if the install command went fine.

Upgrade pip-installed python packages

Display _something_ when an X app fails
When you run an X program from a terminal you can see any errors. But when it's run from another X program (eg from a menu item, from your fluxbox 'keys' file etc) it might just die and you see nothing (except perhaps in .xsession-errors). Instead, launch it via this command and you'll see the termination status, stderr and stdout. eg: "xlaunch firefox" or "xlaunch 'echo stdout; echo stderr >&2; false'": 'echo stdout; echo stderr >&2; false' failed with error 1 STDERR: stderr STDOUT: stdout

List of commands you use most often
Plot your most used commands with gnuplot.

Search and play MP3 from Skreemr
This use the Screemr search engine to play mp3 songs

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: