Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using sleep from sorted by
Terminal - Commands using sleep - 236 results
(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
for a in $(seq 15); do (xset led 3);(xset -led 3);sleep .9;done
while true; do clear;awk '{a[$3]+=1};END{for(x in a){print x,a[x]}}' /proc/[0-9]*/stat; sleep 1; done
while true; do clear; cat /proc/[0-9]*/stat | cut -d' ' -f 3 | sort | uniq -c | awk '{print $2" "$1}'; echo '---'; sleep 1; done
(prefix="10.59.21" && for i in `seq 254`; do (sleep 0.5 && ping -c1 -w1 $prefix.$i &> /dev/null && arp -n | awk ' /'$prefix'.'$i' / { print $1 " " $3 } ') & done; wait)
2014-04-02 11:20:57
User: smoky
Functions: arp awk ping sleep
Tags: ping
1

Waits for all pings to complete and returns ip with mac address

alias oath='temp=$(pbpaste) && oathtool --base32 --totp "YOUR SEED HERE" | pbcopy && sleep 3 && echo -n $temp | pbcopy'
2014-03-14 19:21:18
Functions: alias echo sleep
0

Typing a word in terminal is easier than digging your phone out, opening your two-factor authentication app and typing the code in manually.

This alias copies the one-time code to your clipboard for 3 seconds (long enough to paste it into a web form), then restores whatever was on the clipboard beforehand.

This command works on Mac. Replace pbpaste/pbcopy with your distribution's versions.

while true; do xdotool mousemove_relative 1 1; xdotool mousemove_relative -- -1 -1; sleep $((60 * 4)); done
2014-03-06 00:04:45
User: FreedomBen
Functions: sleep
Tags: xdotool
2

Moves the mouse 1 pixel down and to the right, then immediately back again, every 4 minutes. This keeps screensavers from turning on. I have used this extensively and I've never even noticed the mouse movement because it is so subtle.

while ps -p $PID; do sleep 1; done; script2
2014-02-12 08:07:44
User: sanjiv856
Functions: ps sleep
0

Run one script after another in such a way that second script starts after finishing first one. Without using Pipe | or ampercent && i.e. the first process is already running and you want second one to start after the first one finishes. And this can be done in different folder in case the output of second script will affect the output of first script. So run this on any folder you wish to.

Where $PID is the process id of the already running job (add PID number)

script2 is your script you wish to run after first script ends

sleep 1 is sleep for one second (SUFFIX may be ?s? for seconds (the default), ?m? for minutes, ?h? for hours or ?d? for days, read man sleep)

while pgrep ^dd; do pkill -INFO dd; sleep 10; done
2014-01-28 03:09:25
User: sternebrau
Functions: sleep
Tags: dd progress
0

While a dd is running in one terminal, open another and enter the while loop. The sample output will be displayed in the window running the dd and the while loop will exit when the dd is complete. It's possible that a "sudo" will need to be inserted before "pkill", depending on your setup, for example:

while pgrep ^dd; do sudo pkill -INFO dd; sleep 10; done
while [ 1 ] ;do ps aux|awk '{if ($8 ~ "D") print }'; sleep 1 ;done
yes 'echo $(( RANDOM%100+1 )); sleep 5' | bash
2013-11-09 16:22:59
User: stx
Functions: sleep yes
0

This one is for OS X users: sort -R and shuf aren't available in Lion (10.7.5)

while true; do date; (curl -s -o 1.html http://www.biglion.ru/deals/ebay-80/ &); sleep 5; cat 1.html | grep "&#1082;&#1091;&#1087;&#1086;&#1085;&#1086;&#1074;" | awk -F"<div>" '{print $2}' | awk -F"<span>" '{print $1}'; done
2013-11-08 12:40:05
User: sxiii
Functions: awk cat grep sleep
-1

Processes biglion quantity of sold ebay coupons/bonus codes, so you can know approximate count of users who buyed the coupons and when sales are come up again.

You can change sleep parameter so script will work slowly or faster (default is 5 seconds).

Additional requirements: curl

Standart tools used: awk, date, cat, grep (bash)

while true; do ls -lah && sleep 1; done
2013-10-20 07:16:49
User: exolon
Functions: ls sleep
0

This one works without an external program (watch). Witch is not await able all the time. HINT: use CTRL + C to exit the loop.

clear; tput cup 8 8; for i in $(seq 1 10); do echo -n "$((11-$i)) ";sleep 1; done; tput cup 10 8; echo -e "DONE\n\n"
for i in {1..20}; do fortune -w ; sleep 3; clear; done
2013-08-16 03:06:48
User: snipertyler
Functions: sleep
5

If you're a slow reader and/or you like to ponder, adjust the sleep time to be longer

while curl -dsL example.com 2>&1 | grep 503;do sleep 8;done;echo server up
while true; do curl -vsL -o /dev/null example.com 2>&1 | grep 503 > /dev/null || echo "OK: server is up."; sleep 8; done
while true; do netstat -a|grep WAIT|wc -l; sleep 5; done
2013-06-19 09:19:41
User: adimania
Functions: grep netstat sleep wc
Tags: netstat tcp
0

This has saved me many times while debugging timeout issues to "too many open files" issues. A high number of the order of thousand, indicates that somewhere connection is not being closed properly.

sleep 10; poweroff
2013-04-13 22:07:15
User: xmuda
Functions: sleep
-11

If you are on your bed, waching a movie or if you are downloading something, but you whant to sleep. You can use these easy command to power off after X time. The time is in sec. if you whant to wait 1 H, use:

sleep 3600; poweroff

while :; do n=$(md5 myfile); if [ "$h" != "$n" ]; then h=$n; scp myfile myserver:mydir/myfile; fi; sleep 1; done
while [ 1 ]; do (ping -c 1 google.com || growlnotify -m 'ur wifiz, it has teh sad'); sleep 10; done
sync ; /sbin/sysctl -w vm.drop_caches=3 ; sync ; sleep 2 ; /sbin/sysctl -w vm.drop_caches=0 ;/sbin/swapoff -a ; sleep 2 ;/sbin/swapon -a
while true; do sleep $(($RANDOM%50)); timeout 1 speaker-test -f 20000 -t sine 2>/dev/null; done&
2013-02-14 21:47:40
User: noah018
Functions: sleep
0

This will cause their computer to make a beeping sound after a random amount of time until it is killed.

while true; do (date | tr "\n" ";") && ping -q -c 1 www.google.com|tail -1|cut -d/ -f5 ;sleep 1; done >> uptime.csv
2013-02-06 22:06:09
User: fanchok
Functions: cut date ping sleep tail tr
0

Used in OS X.

tr "\n" ";"

may be replaced by

echo ";"

with linux versions of date.

I reused

ping -q -c 1 www.google.com|tail -1|cut -d/ -f5

while i=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI; sleep 0.5; done