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 tagged curl from sorted by
Terminal - Commands tagged curl - 177 results
expandurl() { curl -sIL $1 | grep ^Location; }
2011-10-19 00:56:53
User: atoponce
Functions: grep
Tags: curl
5

curl(1) is more portable than wget(1) across Unices, so here is an alternative doing the same thing with greater portability. This shell function uses curl(1) to show what site a shortened URL is pointing to, even if there are many nested shortened URLs. This is a great way to test whether or not the shortened URL is sending you to a malicious site, or somewhere nasty that you don't want to visit. The sample output is from:

expandurl http://t.co/LDWqmtDM
curl -u username --silent "https://mail.google.com/mail/feed/atom" | awk 'BEGIN{FS="\n";RS="(</entry>\n)?<entry>"}NR!=1{print "\033[1;31m"$9"\033[0;32m ("$10")\033[0m:\t\033[1;33m"$2"\033[0m"}' | sed -e 's,<[^>]*>,,g' | column -t -s $'\t'
2011-10-15 23:15:52
User: frntn
Functions: awk column sed
2

Just an alternative with more advanced formating for readability purpose. It now uses colors (too much for me but it's a kind of proof-of-concept), and adjust columns.

while sleep 30; do tput sc;tput cup 0 $(($(tput cols)-15));echo -n " New Emails: $(curl -u username:password --silent https://mail.google.com/mail/feed/atom | grep 'fullcount' | grep -o '[0-9]\+')";tput rc; done &
curl pagerank.bz/yourdomain.com
curl http://my-ip.cc/host.json
2011-09-01 00:31:49
User: samleb
0

JSON version.

Additionally it may give your geolocation if it's known by hostip.info

curl http://my-ip.cc/host.xml
2011-09-01 00:30:03
User: samleb
-1

XML version.

Additionally it may give your geolocation if it's known by hostip.info

curl http://my-ip.cc/host.txt
2011-09-01 00:28:49
User: samleb
-1

Additionally it may give your geolocation if it's known by hostip.info

function expand_url() { curl -sI $1 | grep Location: | cut -d " " -f 2 | tr -d "\n" | pbcopy }
2011-08-21 05:30:09
User: gt
Functions: cut grep tr
0

Expand a URL, aka do a head request, and get the URL. Copy this value to clipboard.

curl -s http://www.perl.org/get.html | grep -m1 '\.tar\.gz' | sed 's/.*perl-//; s/\.tar\.gz.*//'
if curl -s -I -H "Accept-Encoding: gzip,deflate" http://example.com/ | grep 'Content-Encoding: gzip' >/dev/null 2>&1 ; then echo Yes; else echo No;fi
curl -I -H "Accept-Encoding: gzip,deflate" http://example.org
isgd () { curl 'http://is.gd/create.php?format=simple&url='"$1" ; printf "\n" }
2011-08-14 23:31:39
User: dbbolton
Functions: printf
Tags: curl shorturl url
1

Check the API. You shouldn't need sed. The print-newline at the end is to prevent zsh from inserting a % after the end-of-output.

Also works with http://v.gd

curl -s --compressed http://funnyjunk.com | awk -F'"' '/ '"'"'mainpagetop24h'"'"'/ { print "http://funnyjunk.com"$4 }' | xargs curl -s | grep -o 'ht.*m/pictures/.*\.jpg\|ht.*m/gifs/.*\.gif' | grep "_......_" | uniq | xargs wget
2011-07-21 15:57:21
User: laniner
Functions: awk uniq xargs
0

If your version of curl does not support the --compressed option, use

curl -s http://funnyjunk.com | gunzip

instead of

curl -s --compressed http://funnyjunk.com
curl -s "$URL" |wc -c
2011-07-18 15:47:57
User: Mozai
Functions: wc
Tags: size curl http
2

Downloads the entire file, but http servers don't always provide the optional 'Content-Length:' header, and ftp/gopher/dict/etc servers don't provide a filesize header at all.

curl --silent "FEED ADDRESS" |sed -e 's/<\/[^>]*>/\n/g' -e 's/<[^>]*>//g
2011-04-11 14:08:50
User: ljmhk
Functions: sed
Tags: curl rss
2

runs an rss feed through sed replacing the closing tags with newlines and the opening tags with white space making it readable.

curl -I g.cn
curl -s http://whatthecommit.com/index.txt | cowsay
function ds { echo -n "search : "; read ST; EST=`php -r "echo rawurlencode('$ST');"`; B64=`echo -n $ST| openssl enc -base64`; curl -s "http://www.commandlinefu.com/commands/matching/$EST/$B64/plaintext" | less -p "$ST"; } ; bind '"\C-k"':"\"ds\C-m\""
2011-02-20 23:46:16
User: cparker
Functions: echo less read
Tags: bash less curl PHP
0

This is a simple bash function and a key binding that uses commandlinefu's simple and easy search API. It prompts for a search term, then it uses curl to search commandline fu, and highlights the search results with less.

Command in description (Your command is too long - please keep it to less than 255 characters)
2011-02-03 08:25:42
User: __
Functions: command less
0
yt2mp3(){ for j in `seq 1 301`;do i=`curl -s gdata.youtube.com/feeds/api/users/$1/uploads\?start-index=$j\&max-results=1|grep -o "watch[^&]*"`;ffmpeg -i `wget youtube.com/$i -qO-|grep -o 'url_map"[^,]*'|sed -n '1{s_.*|__;s_\\\__g;p}'` -vn -ab 128k "`youtube-dl -e ${i#*=}`.mp3";done;}

squeezed the monster (and nifty ☺) command from 7776 from 531 characters to 284 characters, but I don't see a way to get it down to 255. This is definitely a kludge!

curl http://www.discogs.com/search?q=724349691704 2> /dev/null | grep \/release\/ | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/'
curl -I http://localhost
qrurl() { curl -sS "http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=H|0&chl=$1" -o - | display -filter point -resize 600x600 png:-; }
2010-12-16 04:42:05
User: __
4

like 7300, but doesn't clutter your working directory with old qr.*.png files. This will get the QR barcode, and send it right into ImageMagick's 'display' tool. Usage is the same as 7300; just call this function followed by the URL:

qrurl http://xkcd.com
atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n}
2010-12-15 11:03:31
User: Seebi
0

this simply curls the feed and runs a xpath query on it ...

curl -s -O http://s3.amazonaws.com/alexa-static/top-1m.csv.zip ; unzip -q -o top-1m.csv.zip top-1m.csv ; head -1000 top-1m.csv | cut -d, -f2 | cut -d/ -f1 > topsites.txt
2010-11-01 01:25:53
User: chrismccoy
Functions: cut head
Tags: curl unzip cut
-4

this will dump a list of domains one per line into a text file

wget -O xkcd_$(date +%y-%m-%d).png `lynx --dump http://xkcd.com/|grep png`; eog xkcd_$(date +%y-%m-%d).png