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,325 results
gcloud components list | grep "^| Not" | sed "s/|\(.*\)|\(.*\)|\(.*\)|/\2/" | xargs echo gcloud components update
2014-10-13 20:52:25
User: wires
Functions: echo grep sed xargs

Google Cloud SDK comes with a package manager `gcloud components` but it needs a bit of `sed` to work. Modify the "^| Not" bit to change the package selection. (The gcloud --format option is currently broken)

for i in `cat hosts_list`; do RES=`ssh myusername@${i} "ps -ef " |awk '/[p]rocessname/ {print $2}'`; test "x${RES}" = "x" && echo $i; done
2014-10-03 14:57:54
User: arlequin
Functions: awk echo test
Tags: ssh awk test ps

Given a hosts list, ssh one by one and echo its name only if 'processname' is not running.

echo "DISK:";df -Pl | grep -v "Filesystem" | awk '{print $5,$6}' ; echo "MEM:" ; free -mto | awk '{ print $1,$2,$3,$4 }'; echo "CPU:"; top -b -d1 -n1 | grep Cpu | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}';echo "LOAD:"; cat /proc/loadavg
2014-09-29 12:43:52
User: injez
Functions: awk cat df echo free grep top

Monitoring system in one line :

DISK : disk space

MEM: memory ( mem , swap, Total)

CPU : all information about cpu activity

LOAD : load average

for file in $(find /var/backup -name "backup*" -type f |sort -r | tail -n +10); do rm -f $file; done ; tar czf /var/backup/backup-system-$(date "+\%Y\%m\%d\%H\%M-\%N").tgz --exclude /home/dummy /etc /home /opt 2>&- && echo "system backup ok"
2014-09-24 14:04:11
User: akiuni
Functions: date echo file find rm sort tail tar
Tags: backup Linux cron

this command can be added to crontab so as to execute a nightly backup of directories and store only the 10 last backup files.

for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do docker ps | grep $line | awk '{printf $NF" "}' && echo $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB ; done
echo $PATH | tr -s ':' '\n'
for I in *.CR2; do if [ `exiv2 pr -p a -u $I | grep 'xmp.Rating' | awk '{ print $4 }'` == "1" ]; then echo $I; fi; done
find . -type d -print0 | while read -d $'\0' dir; do cd "$dir"; echo " process $dir"; find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \; ; cd -; done
2014-08-25 11:28:43
Functions: cd echo find read rename

This is probably overkill, but I have some issues when the directories have spaces in their names.


find . -type d -print0 | while read -d $'\0' dir; do xxx; done

loops over all the subdirectories in this place, ignoring the white spaces (to some extend).

cd "$dir"; echo " process $dir"; cd -;

goes to the directory and back. It also prints some info to check the progress.

find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \;

renames the file within the current directory.

The whole should work with directories and file names that include white spaces.

tasklist /nh /fi "imagename eq notepad.exe" | findstr /i "notepad.exe" >nul && (echo Notepad is running)|| (Echo Notepad is not running)
2014-08-22 00:52:19
Functions: echo

There are many ways to do it on *nix. But on Windows, it's a bit convoluted.

I use the above command expression in a batch file to check if a process is running already before running it again. I use this is a batch file I created to switch between 2 different versions of PowerBuilder (PB). I wanted to make sure, one version of PB is not running, before letting the user to switch, hence this check. (replace notepad.exe with PB125.exe above).

/nh means no header, /fi means filter. We are filtering for Notepad.exe only above. Then, we take that and look for Notepad.exe using a FindStr command. It will still work, even if we don't have those 2 flags, but it makes finding the right program quicker.

&& and || are part of the conditional expressions see here: http://www.robvanderwoude.com/condexec.php. We use these to print for the IF...ELSE condition.

>nul is the equivalent of Unix /dev/null

Rest is self explanatory, I think.

echo "bored of the awaiting moderation"
YEAR=2015; echo Jul $(ncal 7 $YEAR | awk '/^Fr/{print $NF}')
2014-08-17 11:12:09
User: andreasS
Functions: awk echo
Tags: awk date

Calculate the date of Sysadmin day (last Friday of July) of any given year

if [ "`curl -s --head domain.tld | grep HTTP | cut -d" " -f2`" != "200" ];then echo "error"; echo "doing else" ;fi
echo 1 > /proc/sys/sunrpc/nfs_debug
2014-08-12 14:40:55
User: harpo
Functions: echo

echo 1 > /proc/sys/sunrpc/nfs_debug && tail -f /var/log/messages

to debug NFS issues.

e() { echo $(curl -o /dev/null --silent --head --write-out '%{http_code}\n' $1); }
2014-08-11 20:51:45
Functions: echo

this function will give you a status webpage code using curl.

eval echo $(echoprint-codegen "/path/to/file.mp3"| jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash
2014-08-08 21:14:53
User: glaudiston
Functions: echo eval

echoprint identify your song, then return artist, song name and album name(release) in a JSON. jq parse it and mp3info set the data in your mp3 file.

of course it depends on:




You need to set the environment variable


You can use it with find, but probably will bypass the 120 request/minute of developer account key. So, use a sleep to do it.

Something like:

find -name \*.mp3 | while read $f; do eval echo $(echoprint-codegen "$f" | jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash; sleep 1; done
[ `curl 'http://crl.godaddy.com/gds5-16.crl' 2>/dev/null | openssl crl -inform DER -noout -nextupdate | awk -F= '{print $2}' | xargs -I{} date -d {} +%s` -gt `date -d '8 hours' +%s` ] && echo "OK" || echo "Expires soon"
2014-08-07 17:18:38
User: hufman
Functions: awk date echo xargs
Tags: openssl

Downloads a CRL file, determines the expiration time, and checks when it will expire

(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
echo "scale=1000; 4*a(1)" | bc -l
2014-07-31 19:13:26
User: regulatre
Functions: bc echo

Change the scale to adjust number of decimal places

prefix the command with "time" to benchmark the computer (compare how long it takes to calculate 10000 digits of pi on various computers).

changeFolder() { if [ $# -ne 2 ]; then echo "Usage: changeFolder old new"; return; fi; old=$(pwd); folder=$(echo "$old" | sed -e "s/$1/$2/g"); if [ ! -d "$folder" ]; then echo "Folder '$folder' not found."; return; fi; echo "$old -> $folder"; cd $folder;}
2014-07-29 15:36:32
User: Dracks
Functions: cd echo sed

change the path where you are, when is executed, is usefule when you've got folders to classify something like a tags, you've got devel/dist, android/ios, etc. like:



You can change between devel/project folder to dist/project without leave project.

If somebody has a better idea to do that without replace command.

echo "import uuid\nimport sys\nsys.stdout.write(str(uuid.uuid4()))" | python
2014-07-23 07:43:01
User: tippy
Functions: echo
Tags: python uuid

piped this to pbcopy (OSX only) you got a uuid in the pasteboard

echo {-1..-5}days | xargs -n1 date +"%Y-%m-%d" -d
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash; mv git-completion.bash ~/.git-completion.bash; echo "source ~/.git-completion.bash" > ~/.bashrc; source ~/.git-completion.bash
2014-07-22 14:21:00
User: servel333
Functions: echo mv wget

Downloads this raw script https://github.com/git/git/blob/master/contrib/completion/git-completion.bash from Github, copies it to your home directory, autoloads it in ~/.bashrc and sources it.

macdst="5873b856445f";macsrc="d2a791e1715a";pkt="d4c3b2a1020004000000000000000000ffff000001000000e3eab353fa1f 0b007400000074000000$macdst $macsrc 0842ffffffffffff";for i in {1..16}; do pkt="$pkt $macdst"; done; echo "$pkt" | xxd -r -p > magicpacket.pcap
2014-07-02 17:37:44
Functions: echo

just set macdst to the mac address of the system

you wish to wake up, the macsrc is optional but helps

use tcpreplay to broadcast or wireshark to view

ssh <user>@<ip address> $(echo wmic process where \"name like \'%<process to kill>%\'\" delete)
2014-07-02 04:41:05
User: adanisch
Functions: echo ssh

Tested on Windows 8 w/SSH, Cygwin - it can be tricky to quote if you dont use the $(..) syntax to echo it back out

echo "btrfs checksum error(s) on: " && grep "btrfs: checksum error at logical" /var/log/messages | sed -e 's/^.*\( dev .*\)\(, sector.*\)\(path\: .*\))/\t\1, \3/' | sort | uniq