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
curl -u $USERNAME:$PASSWORD "http://dynupdate.no-ip.com/nic/update?hostname=$HOSTNAME"
python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
2012-05-31 17:14:17
User: shr386
Functions: python
1

(1) required: python-googl ( install by: pip install python-googl )

(2) get from google API console https://code.google.com/apis/console/

curl ifconfig.me/all
2012-05-16 18:22:28
User: pykler
9

Gets all kind of info, ifconfig.me rocks ...

for just the ip addess you can use ifconfig.me or ifconfig.me/ip

cat urls.txt | xargs -n1 curl -O --max-time 10 --retry 3 --retry-delay 1
curl -su username:passwd https://mail.google.com/mail/feed/atom | xmlstarlet sel -N x="http://purl.org/atom/ns#" -t -m //x:entry -v 'concat(position(), ":", x:title)' -n
shorty () { curl -s https://www.googleapis.com/urlshortener/v1/url\?key\=API_KEY -H 'Content-Type: application/json' -d '{"longUrl": "'"$1"'"}' | egrep -o 'http://goo.gl/[^"]*' }
2012-04-26 18:30:50
User: cybersiddhu
Functions: egrep
1

First get a api key for google url shortner from here https://developers.google.com/url-shortener/

Then replace the API_KEY in the command

watch 'curl -s --location -I http://any.site.or.url | grep -e "\(HTTP\|Location\)"'
2012-04-23 17:05:29
User: theist
Functions: grep watch
3

Watches the headers of a curl, following any redirects and printing only the HTTP status and the location of the possible redirects.

curl ip.nu
curl -I -L http://t.co/mQUxL6yS
curl -s mobile.twitter.com/search | sed -n '/trend_footer_list/,/\ul>/p' | awk -F\> '{print $3}' | awk -F\< '{print $1}' | sed '/^$/d'
2012-03-15 17:17:06
User: articmonkey
Functions: awk sed
Tags: twitter awk curl
0

Prints top 5 twitter topics. Not very well written at all but none of the others worked.

curl -s -d "CSField=Name" -d "CSInput=BostonUCompSci" http://torstatus.blutmagie.de/index.php | grep -oP "ip=\K(\d+)(\.\d+){3}"
2012-03-09 16:52:27
User: JisSey
Functions: grep
0

Reciprocally, we could get the node name from a give Tor IP address =>

ip2node() { curl -s -d "QueryIP=$1" http://torstatus.blutmagie.de/tor_exit_query.php | grep -oP "Server name:.*'>\K\w+" ; }

ip2node 204.8.156.142

BostonUCompSci

curl 'https://www.kernel.org/kdist/finger_banner'
2012-03-04 21:10:19
User: Testuser_01
0

Gets the (previously obtainable with:

finger @kernel.org

) info of the latest linux kernel versions available.

open R,"curl -s http://feeds2.feedburner.com/Command-line-fu|xml2|"; while(<R>){ chomp; m(^/rss/channel/item/title=) and do{ s/^.*?=//; ($t,$d,$l)=($_,undef,undef) }; m(^/rss/channel/item/description=) and do{ s/^.*?=//; push @d,$_ }; m(^/rss/channel/item
cmdfu(){ local t=~/cmdfu;echo -e "\n# $1 {{{1">>$t;curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext"|sed '1,2d;s/^#.*/& {{{2/g'>$t;vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;rm $t; }
2012-02-21 05:43:16
User: AskApache
Functions: echo rm sed vim
6

Here is the full function (got trunctated), which is much better and works for multiple queries.

function cmdfu () {

local t=~/cmdfu;

until [[ -z $1 ]]; do

echo -e "\n# $1 {{{1" >> $t;

curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext" | sed '1,2d;s/^#.*/& {{{2/g' | tee -a $t > $t.c;

sed -i "s/^# $1 {/# $1 - `grep -c '^#' $t.c` {/" $t;

shift;

done;

vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;

rm $t $t.c

}

Searches commandlinefu for single/multiple queries and displays syntax-highlighted, folded, and numbered results in vim.

curl -s ifconfig.me|tee >(xargs geoiplookup)
2012-02-09 20:30:26
Functions: tee xargs
Tags: tee curl geoip
0

Show external IP and geolocation information.

Primary feature is the use of tee to echo IP _and_ send to geoiplookup command...Use IP as input for as many commands as you want with more >( [command] )

Thanks to http://www.commandlinefu.com/commands/view/6334/

Requires MaxMind DB and geoiplookup tool.

Sample output has IP obfuscated on first line, lines 2-4 from having MaxMind Country && MaxMind City DBs installed

curl $URL -s -L -o /dev/null -w '%{url_effective}'
2012-01-25 16:11:24
User: labynocle
Tags: curl redirect url
0

Sometimes it could be very useful to obtain the final URL you'll use after several redirects.

(I use this command line for my automated tests to check if every redirections are ok)

wget ifconfig.me/ip -q -O -
say() { curl -sA Mozilla -d q=`python3 -c 'from urllib.parse import quote_plus; from sys import stdin; print(quote_plus(stdin.read()[:100]))' <<<"$@"` 'http://translate.google.com/translate_tts' | mpg123 -q -; }
curl icanhazip.com
for i in {1..40};do echo -n $i. $(date +%H:%M:%S):\ ; (time curl 'http://ya.ru/' &> /dev/null) 2>&1|grep real;sleep 1;done
2011-11-11 10:40:38
User: AntonyC
Functions: date echo grep sleep time
Tags: curl
-1

This uses curl to find out the access times of a web service

curl -O http://www.site.com/img/image[001-175].jpg
curl -b cookie.txt http://www.site.com/download/file.txt
curl -c cookie.txt -d username=hello -d password=w0r1d http://www.site.com/login
curl sputnick-area.net/ua
2011-10-24 09:57:50
User: sputnick
Tags: curl headers
-3

That's useful when you're doing some web scraping http://en.wikipedia.org/wiki/Web_scraping and you're trying to test your possibly fake user-agent.

expandurl() { curl -sIL $1 2>&1 | awk '/^Location/ {print $2}' | tail -n1; }
2011-10-19 01:35:33
Functions: awk tail
Tags: curl
0

This shell function uses curl(1) as it is more portable than wget(1) across Unices, to show what site a shortened URL is pointing to, even if there are many nested shortened URLs. It is a refinement to www.commandlinefu.com/commands/view/9515/expand-shortened-urls to make it better for use in scripts. Only displays final result.

expandurl http://t.co/LDWqmtDM