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 at from sorted by
Terminal - Commands using at - 30 results
echo ?ls -l? | at midnight
echo ?ls -l? | at 10am Jul 21
echo "aplay ring.wav" | at now + 25 min
2013-03-22 04:27:57
User: liancheng
Functions: at echo
0

The Pomodoro Technique is a time management method developed by Francesco Cirillo in the late 1980s. The technique uses a timer to break down periods of work into 25-minute intervals called 'Pomodori' (from the Italian word for 'tomatoes') separated by short breaks.

You need to prepare a short .wav file (the "ring.wav" in the sample command line). This command will trigger aplay to play ring.wav 25 minutes from now on, which can be used as a poor man's pomodoro timer.

ls -qaltr # list directory in chronological order, most recent files at end of list
2013-02-25 14:14:44
User: mpb
Functions: at ls
7

I find it very handy to be able to quickly see the most recently modified/created files in a directory.

Note that the "q" option will reveal any files with non-printable characters in their filename.

at <date> < jobs.sh
at midnight<<<'ls -l'
at 8:30 <<<'mpc volume 20; mpc play; for i in `seq 1 16`; do sleep 2; mpc volume +5; done'
2011-11-30 17:51:27
User: mechmind
Functions: at sleep
Tags: alarm mpd wakeup
7

There are a lot of commands, which invokes your player at specified time. But I prefer not to jump from by bed, when alarm start to play. Instead, this script increases volume of mpd over time, which much more pleasant when you just woke up :)

echo "notify-send TimeToQuit" | at 10:22
echo 'mail -s "Call your wife" 13125551234@tmomail.net' |at now+15min
2011-07-20 18:53:01
User: raulyca
Functions: at echo
3

Send an e-mail to SMS reminder in 15 minutes from now, to call my wife. See list of carriers bellow

Carrier Email to SMS Gateway

Alltel [10-digit phone number]@message.alltel.com

AT&T (formerly Cingular) [10-digit phone number]@txt.att.net

[10-digit phone number]@mms.att.net (MMS)

[10-digit phone number]@cingularme.com

Boost Mobile [10-digit phone number]@myboostmobile.com

Nextel (now Sprint Nextel) [10-digit telephone number]@messaging.nextel.com

Sprint PCS (now Sprint Nextel) [10-digit phone number]@messaging.sprintpcs.com

[10-digit phone number]@pm.sprint.com (MMS)

T-Mobile [10-digit phone number]@tmomail.net

US Cellular [10-digit phone number]email.uscc.net (SMS)

[10-digit phone number]@mms.uscc.net (MMS)

Verizon [10-digit phone number]@vtext.com

[10-digit phone number]@vzwpix.com (MMS)

Virgin Mobile USA [10-digit phone number]@vmobl.com

if [ $(date +%u) -lt 6 ];then AT="tomorrow"; else AT="next monday";fi;echo "beep" | at ${AT}
2011-06-01 14:15:11
User: eduo
Functions: at date echo
1

Line can be modified as needed. This considers weekdays to be Mon-Fri. If run any working day it'll provide a parameters for the next working day for "at".

"beep" provided as a sample command.

This can be modified easily to include wait time. If you need something to run "D" days after today:

# D=4;if [ $(date +%u --date="${D} days") -lt 5 ];then AT="+${D} days";else AT="next monday";fi; echo "beep" | at noon ${AT}

echo "shutdown -h now" | sudo at now + 4 hours
2011-05-02 15:29:48
User: depesz
Functions: at echo sudo
-2

Benefit is that it doesn't make you keep the terminal open.

The command is too big to fit here. :( Look at the description for the command, in readable form! :)
2011-01-05 02:45:28
User: hunterm
Functions: at command
-6

Yep, now you can finally google from the command line!

Here's a readable version "for your pleasure"(c):

google() { # search the web using google from the commandline # syntax: google google query=$(echo "$*" | sed "s:%:%25:g;s:&:%26:g;s:+:%2b:g;s:;:%3b:g;s: :+:g") data=$(wget -qO - "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$query") title=$(echo "$data" | tr '}' '\n' | sed "s/.*,\"titleNoFormatting//;s/\":\"//;s/\",.*//;s/\\u0026/'/g;s/\\\//g;s/#39\;//g;s/'amp;/\&/g" | head -1) url="$(echo "$data" | tr '}' '\n' | sed 's/.*"url":"//;s/".*//' | head -1)" echo "${title}: ${url} | http://www.google.com/search?q=${query}" }

Enjoy :)

bindkey ^f at "#" kill
2010-10-07 12:01:38
Functions: at
Tags: screen
0

Kills all windows in a gnu screen session and terminates it , on pressing Control-f , useful in closing screen session with large number of windows . Add it to your screenrc .

bindkey ^l at "#" log on bindkey ^o at "#" log off
2010-10-07 11:55:25
Functions: at
1

The command when added in screenrc enables logging all open windows by using the C-l (control-l key combination) and disable by C-o . The lines need to be added in separate lines .

echo notify-send test | at now+1minute
2010-08-08 03:11:11
User: polar
Functions: at echo test
Tags: notify-send
4

The simplest way to do it.

Works for me, at least. (Why are the variables being set?)

echo "export DISPLAY=:0; export XAUTHORITY=~/.Xauthority; notify-send test" | at now+1minute
2010-07-27 00:10:08
Functions: at echo
Tags: notify-send
20

You can write a script that does this :

remind <minutes> [<message>]
for i in be bg cz de es fi fr hu it lv lu at pl pt ro sk si ; do echo -n "$i " ; wget -q -O - http://www.expansys.$i/d.aspx?i=196165 | grep price | sed "s/.*<p id='price'><strong>&euro; \([0-9]*[,.][0-9]*\).*/\1/g"; done
2010-03-18 15:13:20
User: betsubetsu
Functions: at bg echo grep sed wget
2

You think Expansys in all these countries will sell the HTC Desire for the same price? Well, you'll be surprised. Most of them will be sold at 499.99 EUR but the cheapest can be found in Germany and the most expensive, in Belgium.

echo "DISPLAY=$DISPLAY xmessage setup suphp perms htscanner acct#101101 host2.domain.com" | at 23:00 Feb 8
2010-02-04 04:26:24
User: op4
Functions: at echo
1

setup for reminder in 5 days, added the date in the future. To run a job at 4pm three days from now, you would do at 4pm + 3 days, to run a job at 10:00am on July 31, you would do at 10am Jul 31 and to run a job at 1am tomorrow, you would do at 1am tomorrow.

echo "DISPLAY=$DISPLAY xmessage convert db to innodb" | at 00:00
xmms2 pause && echo "xmms2 play" | at now +5min
2009-08-30 04:35:10
User: Vrekk
Functions: at echo
2

you can also run "xmms2 pause & at now +5min

at 6:00 <<< "xmms2 play"
2009-08-27 16:30:07
User: Mikachu
Functions: at
3

I like the order of the arguments better this way.

echo "xmms2 play" | at 6:00
2009-08-26 04:20:24
User: Vrekk
Functions: at echo
1

Nice little alarm clock to wake you up on time (hopefully).

You can also do 'echo "vlc path/to/song" | at 6:00

echo init 0 | at now + 2 hours
echo "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at now + 3 hours 1>&2 &>/dev/null
2009-08-18 07:31:17
User: AskApache
Functions: at echo
1

This is helpful for shell scripts, I use it in my custom php install script to schedule to delete the build files in 3 hours, as the php install script is completely automated and is made to run slow.

Does require at, which some environments without crontab still do have.

You can add as many commands to the at you want. Here's how I delete them in case the script gets killed. (trapped)

atq |awk '{print $1}'|xargs -iJ atrm J &>/dev/null

Keys=$HOME/.ssh/authorized_keys;Back=$Keys.tmp.bak;Time=${1:-15};cp $Keys $Back;cat /dev/stdin >>$Keys;echo mv $Back $Keys|at now+${Time}minutes;
2009-07-15 23:45:02
User: 5z474n
Functions: at mv
1

If you frequently need to connect to your ubersecure mainframe from various uberunsafe machines, you have to face difficult decision: (a) type the password everytime during the session (lame), (b) add local public key to mainframes authorized_keys file (unsafe), (c) as above, but remove this key at the end of the session (pain in the a55). So let's say you save The Command to tempauth file in bin directory of your mainframe's account and make it executable. Then, while you're on one of these unsafe ones, do:

cat $HOME/.ssh/id_rsa.pub|ssh 5z474n@mainframe.nl bin/tempauth 30

and password prompts stop the harassment for 30 minutes and you don't have to care to remove the unsafe key after that.