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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

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 272 weeks and 2 days ago

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

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

Comment by SuperFly 272 weeks and 2 days 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 272 weeks and 2 days ago

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

Comment by leovailati 272 weeks and 2 days 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 272 weeks and 1 day 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 272 weeks and 1 day 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 272 weeks and 1 day 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 272 weeks 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 272 weeks ago

Your point of view

You must be signed in to comment.