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 by houghi from sorted by
Terminal - Commands by houghi - 19 results
if [ $EUID -ne 0 ];then if [ -t $DISPLAY ]; then sudo $0 "$*"; exit; else xdg-su -c "$0 $*"; exit;fi;fi
2011-08-24 18:03:46
User: houghi
Functions: sudo
1

Will run the script as root and exit if the wrong or no password is given. Also will keep the parameters active if any where given.

mogrify -modulate 100,100,70 ../../icons/32x32/*.png
wget -r -A .pdf -l 5 -nH --no-parent http://example.com
2011-06-09 17:17:03
User: houghi
Functions: wget
Tags: wget pdf
7

See man wget if you want linked files and not only those hosted on the website.

cat /sys/class/net/*/address
2011-06-03 05:52:37
User: houghi
Functions: cat
Tags: mac
4

No need for the ls -r and a sort is also not really needed.

lynx -dump -nolist http://whatthecommit.com/|sed -n 2p
2011-04-17 17:45:18
User: houghi
Functions: sed
-4

Fetch comical VC commit messages from whatthecommit.com

mmv "*-*.mp3" "#1.mp3"
2011-03-06 13:41:54
User: houghi
-1

replace the "-" by the character you wish. If you have multiple extentions, like jpef, jpg and JPG you could use

mmv "*-*.*" "#1.#3"
dos2unix <file>
echo "Terrorist threat level: `sed $(perl -e "print int rand(99999)")"q;d" /usr/share/dict/words`"
2011-01-28 09:49:37
User: houghi
Functions: echo
-1

Numbers are less understandable then words. Also this may put out a different result.

mmv "*.txt" "#1.md"
2010-12-09 19:14:07
User: houghi
Tags: batch rename
4

Batch rename extension of all files in a folder, in the example from .txt to .md

mmv most likely must be installed, but is very powerfull when you want to move/copy/append/link multiple files by wildcard patterns.

radio() { if [ "$(pidof mpg123)" ] ; then killall mpg123; else mpg123 -q -@ http://173.236.29.51:8200 & fi }
2010-11-14 16:27:04
User: houghi
Functions: killall mpg123
1

Place it in your bashrc and running the command radio it will turn on or off each time it runs. Only one command needed. Obviously you can set it to any station you like.

killall xmms
for I in `/sbin/lspci |awk '/VGA/{print $1}'`;do /sbin/lspci -v -s $I;done
l=12765843;curl -s http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{print $2 "\n" $4;}'
2010-10-24 20:02:30
User: houghi
Functions: awk grep
3

This will get the sunrise and sunset times of a specific location. To be able to determine $l you need to first go to http://weather.yahoo.com/ and look up your location. The last numbers in the URL will be the $l

Instead of forecastrss?w=$l you can also use forecastrss?p=$l and use the RSS link of the city you found.

Also see http://developer.yahoo.com/weather/ for more information

mogrify -trim *png
2010-10-21 15:09:33
User: houghi
Tags: convert png trim
1

That should be a short as it can get.

findlocation() {place=`echo $@`; lynx -dump "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | egrep "address|coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}
2010-10-18 21:59:26
User: houghi
Functions: egrep sed
Tags: curl google
0

Just a few minor changes.

First the usage of lynx instead of curl so no sed is needed to revert the spaces. Then the usages of egrep instead of grep -e to save a few characters and last the removal of the extra 0.

geoiplookup <ipadress>
2010-10-13 09:19:17
User: houghi
2

GeoIP Needs to be installed. Can be done from some distro's or via MaxMind.com for free. There even is a free city database availabble. If the GeoLiteCity is downloaded and installed it will also find more information

geoiplookup -f /var/lib/GeoIP/GeoLiteCity.dat commandlinefu.com

GeoIP City Edition, Rev 1: US, NJ, Absecon, 08201, 39.420898, -74.497704, 504, 609

j=0;while true; do let j=$j+1; for i in $(seq 0 20 100); do echo $i;sleep 1; done | dialog --gauge "Install part $j : `sed $(perl -e "print int rand(99999)")"q;d" /usr/share/dict/words`" 6 40;done
2010-10-08 12:12:00
User: houghi
Functions: echo seq sleep
15

This will turn it in an infinite loop and also shows random words from a file, so it won't be the same each time and also not just a number.

killall <name>
lynx -source http://www.lipsum.com/feed/xml?amount=3|perl -p -i -e 's/\n/\n\n/g'|sed -n '/<lipsum>/,/<\/lipsum>/p'|sed -e 's/<[^>]*>//g'
2010-04-26 17:26:44
User: houghi
Functions: perl sed
5

This will generate 3 paragraphs with random text. Change the 3 to any number.