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

Save xkcd to a pdf with captions

Terminal - Save xkcd to a pdf with captions
curl -sL xkcd.com | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > xkcd.pdf
2010-03-03 03:41:31
User: matthewbauer
Functions: cat cut grep sed
6
Save xkcd to a pdf with captions

Saves to a PDF with title and alt text of comic.

As asked for on http://bbs.archlinux.org/viewtopic.php?id=91100

Change xkcd.com to dynamic.xkcd.com/comics/random for a random comic.

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

Error:

convert: Non-conforming drawing primitive definition `s' @ draw.c/DrawImage/3123.

Result:

Alt text garbled

Comment by oshazard 230 weeks and 1 day ago

convert: unable to read font `/usr/share/fonts/default/TrueType/arial.ttf'.

convert: Non-conforming drawing primitive definition `m'.

Comment by SuperFly 230 weeks and 1 day ago

convert: unable to read font `/usr/share/fonts/default/TrueType/arial.ttf'.

if you got this, try this:

add -font "helvetica" to the convert command

e.g.: ...| convert -font "helvetica" png:- ...

this:

convert: Non-conforming drawing primitive definition `m'.

is still coming up, but you'll see the text in the pdf

Comment by nbk1971 230 weeks and 1 day ago

nice, but didn't work - same problem as comments above

Comment by leovailati 230 weeks and 1 day ago

I think I've fixed those problems please try it again.

Remember it saves to a pdf file so you should have an "xkcd.pdf" in your local directory.

Comment by matthewbauer 230 weeks ago

It worked aces for me; I was the first to give it a thumbs up. :P

Something I've considered giving a go, but have yet to - converting it to vector and doubling (or tripling) in size before saving to pdf. Also it would be pretty sweet to name each pdf "comicNumber.pdf" rather than just xkcd.pdf. If I could do that, and successfully achieve the vector "zoom" effect, i'd totally make this a daily cron. :)

Comment by trench 230 weeks ago

There is no need for the temp file. You can use convert on a URL. So the major thing might be

IMG=`curl -sL xkcd.com| grep '<img [^>]*/><br/>'|awk -F\" '{print $2}'`;convert $IMG -gravity south -draw "text 0,0 \"$IMG\"" pdf:- > xkcd.pdf
Comment by houghi 230 weeks ago

@trench

Try this:

number=100; for a in $(seq 1 $number); do curl -sL xkcd.com/$a | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > /tmp/$a.pdf; done; gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=xkcd.pdf $(seq 1 $number | sed -r 's/(.*)/\/tmp\/\1.pdf/'); rm /tmp/a /tmp/*.pdf
Comment by matthewbauer 229 weeks and 6 days ago

@houghi

The problem is it gives the URL of the xkcd comic not the alt text

@trench

Actually this is more what you want:

number=100; mkdir xkcd; for a in $(seq 1 $number); do curl -sL xkcd.com/$a | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > xkcd/$a.pdf; done
Comment by matthewbauer 229 weeks and 6 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts