What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using echo from sorted by
Terminal - Commands using echo - 1,324 results
echo $(($(find . -name "pattern" -type f -printf "+%s")))
2014-01-16 03:14:36
User: flatcap
Functions: echo find

Use find's internal stat to get the file size then let the shell add up the numbers.

IFS=$(echo -en "\n\b"); mkdir Epub; for i in `find . | grep epub`; do echo "epub: $i"; mv -v "$i" Epub; done
for s in 172.16.{1,2}2.9{0,1,2}; do echo "Repairing node $s..."; nodetool -h $s repair -pr; done
2014-01-01 17:05:40
User: mrwulf
Functions: echo

Repair each node in sequence. Make sure you change the IP replacements to match your environment

finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}
2013-12-30 07:47:41
User: lowjax
Functions: awk echo return sed

Pass the files path to finfo(), can be unix path, dos path, relative or absolute. The file is converted into an absolute nix path, then checked to see if it is in-fact a regular/existing file. Then converted into an absolute windows path and sent to "wmic". Then magic, you have windows file details right in the terminal. Uses: cygwin, cygpath, sed, and awk. Needs Windows WMI "wmic.exe" to be operational. The output is corrected for easy...

finfo notepad.exe finfo "C:\windows\system32\notepad.exe" finfo /cygdrive/c/Windows/System32/notepad.exe finfo "/cygdrive/c/Program Files/notepad.exe" finfo ../notepad.exe
cd ~/wallpapers;arr=( * );num_wallpapers=${#arr[@]};wallpaper=${arr[$(echo $RANDOM%$num_wallpapers|bc)]};feh --bg-fill $wallpaper
2013-12-30 01:56:24
User: Evidlo
Functions: cd echo

Generates a bash array and uses it to select a random image from ~/wallpapers.

for i in *.djvu; do djvu2pdf $i && echo "Finished -> $i"; done;
for i in $(ls *.mp3); do mplayer $i && echo "delete it? [y/n]" && read trash && if [ "$trash" == "y" ]; then rm $i; fi; do
2013-12-23 20:09:56
User: wibbel4
Functions: echo ls read rm

Old drive with lots of music or unsorted drive? This command will play all mp3 files in a folder and after playing one song or pressing q, it will ask you if you want to delete the file.

for i in */; do echo $(find $i -type f -regextype posix-extended -regex ".*\.(mp3|ogg|wav|flac)" | wc -l) $i ; done
find . -type d -maxdepth 1 -print0 | xargs -0 -I{} sh -c 'find "{}" -type f | grep "ogg\|mp3\|wav\|flac$" | wc -l | tr -d "\n"; echo " {}"'
2013-12-22 13:40:29
User: dbrgn
Functions: echo find grep sh tr wc xargs

This lists the number of ogg/mp3/wav/flac files in each subdirectory of the current directory. The output can be sorted by piping it into "sort -n".

echo "text to prepend" | cat - file
2013-12-18 15:54:17
User: leni536
Functions: cat echo
Tags: cat replace

Prepend text to a file. It doen't need temporary files, ed or sed.

ram() { mt=/mnt/ram && grep "$mt" < /proc/mts > /dev/null; if [ $? -eq 0 ] ; then read -p"Enter to Remove Ram Partition ";sudo umount "$mt" && echo $mt 0; else sudo mt -t tmpfs tmpfs "$mt" -o size=$(( ${1:-1} * 1024 ))m && echo $mt '-' "${1:-1}"gb; fi; }
2013-12-13 05:22:02
User: snipertyler
Functions: echo grep mt read sudo umount
Tags: sudo ram tmpfs

Creates a temporary ram partition

To use:

ram 3

to make a 3gb partition (Defaults to 1gb)

for fn in *.epub; do echo mv \"$fn\" \"`echo "$fn" | sed -E 's/\.*\/*(.*)( - )(.*)(\.[^\.]+)$/\3\2\1\4/' | sed -E 's/(.*) ([^ ]+)( - )(.*)/\2, \1\3\4/' `\";done | sh
2013-11-30 05:29:52
User: woohoo
Functions: echo mv sed

If you want to test output, run it like this:

for fn in *.epub; do echo mv \"$fn\" \"`echo "$fn" | sed -E 's/\.*\/*(.*)( - )(.*)(\.[^\.]+)$/\3\2\1\4/' | sed -E 's/(.*) ([^ ]+)( - )(.*)/\2, \1\3\4/' `\";done > rename.txt

for i in */; do echo run_command "${i}"; done
2013-11-25 18:33:26
User: mirams
Functions: echo

Change the "run_command" to whatever command you want, and remove the "echo" to run it once you are happy.

echo "Hello WOrld"
2013-11-24 10:26:50
User: Abhay_k
Functions: echo
Tags: echo

This will display --> Hello World

for file in $(git ls-files | grep old_name_pattern); do git mv $file $(echo $file | sed -e 's/old_name_pattern/new_name_pattern/'); done
nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
2013-11-12 14:00:11
User: gvitalie
Functions: echo

-k, --keep-open will keep connection alive, and we could exclude using 'while true'

nc is such a powerful command, it could be used instead of any OS! :p

nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
2013-11-12 13:43:38
User: gvitalie
Functions: echo

nc is such a powerful command, it could be used instead of any OS! :p

(echo >/dev/tcp/localhost/25) &>/dev/null && echo "TCP port 25 open" || echo "TCP port 25 close"
2013-11-12 02:11:01
User: YouM
Functions: echo

Check trough unix sockets if tcp port is open or close

echo $(curl http://ipecho.net/plain 2> /dev/null)
echo $(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10)
2013-11-07 21:51:38
User: santizo
Functions: echo head tr

Uses urandom and tr to generate a random password. Change the value of head -c## for the lenght of the password.

echo "rootgot" | awk 'BEGIN{FIELDWIDTHS="4 3"}{print $2$1}'
# [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "Alive"
for key in `echo 'KEYS pattern*' | redis-cli | awk '{print $1}'`; do echo DEL $key; done | redis-cli
2013-10-29 04:50:35
User: caiosba
Functions: awk echo

Delete items from Redis, using redis-cli, by matching a key pattern.

while true; do echo "message here" | mutt [email protected] ; done
2013-10-27 23:32:54
User: KcidKcus
Functions: echo

To send a text message to a phone, you need to send the text message via email. To find out how to send text messages to cell phones via email, go here - http://en.wikipedia.org/wiki/List_of_carriers_providing_Email_or_Web_to_SMS and find the carrier of the cell phone you want to send the text message to.

logme(){ echo "$(date +%d-%m-%Y-%H:%M) => $0 @ $1 returned error" >> persoscript.log }
2013-10-22 15:55:01
User: qcjn
Functions: echo
Tags: logging

Put this logging function in you're script, when need it call it.

command || logme "Error with command"