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

2012-05-20 - test
test
2012-05-20 - test
test
2012-05-20 - test
test
2012-05-20 - Test tweets
YU not working?
Hide

Tags

Hide

Functions

Commands tagged pdf

Commands tagged pdf from sorted by
Terminal - Commands tagged pdf - 42 results
pdftk A=1.pdf B=2.pdf C=3.pdf cat C A output CA.pdf
pdftk 1.pdf 2.pdf cat output 12.pdf
pdfinfo file.pdf | grep "^Pages: *[0-9]\+$" | sed 's/.* //'
pdftk file.pdf dump_data output | grep -i Num
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
2012-02-29 21:30:20
User: DavideRiboli
Functions: gs
0

Useful if you want to reduce PDF file size using command line by ghostscript.

enscript -L1 -b'||Page $% of $=' -o- < <(for i in $(seq "$(pdftk "$1" dump_data | grep "Num" | cut -d":" -f2)"); do echo; done) | ps2pdf - | pdftk "$1" multistamp - output "${1%.pdf}-header.pdf"
2012-01-27 12:26:33
User: captaincomic
Functions: seq
0

Put this code in a bash script. The script expects the PDF file as its only parameter.

It will add a header to the PDF containing the page numbers and output it to a file with the suffix "-header.pdf"

Requires enscript, ps2pdf and pdftk.

echo "This text gets stamped on the top of the pdf pages." | enscript -B -f Courier-Bold16 -o- | ps2pdf - | pdftk input.pdf stamp - output output.pdf
2012-01-03 14:58:10
User: svg
Functions: echo
16

To quickly add some remark, comment, stamp text, ... on top of (each of) the pages of the input pdf file.

find -iname "*.pdf" -exec pdfinfo -meta {} \;|awk '{if($1=="Pages:"){s+=$2}}END{print s}'
2011-12-13 15:02:11
User: Barabbas
Functions: awk find
Tags: awk find pdf count sum
0

This sums up the page count of multiple pdf files without the useless use of grep and sed which other commandlinefus use.

pdfcrack <FILE>
for F in *.pdf ; do qpdf --password=your_password --decrypt "$F" "$(basename $F .pdf)-nopw.pdf" ; done
2011-11-30 21:35:33
User: slc66
0

This command line will remove password from all PDF files in the current folder. It use qpdf.

ls -1 $PATH*/* | xargs file | awk -F":" '!($2~/PDF document/){print $1}' |xargs rm -rf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=14 -dLastPage=17 -sOutputFile=OUTPUT.pdf ORIGINAL.pdf
mergepdf() { gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf "$@" }
2011-07-28 11:12:15
Functions: gs
0

This is an expansion on a previous entry, which I've wrapped in a function and placed in my profile. The "$@" is a positional parameter, much like "$*", but the parameters are passed on intact, without interpretation or expansion; so you can simply call the function like this:

mergepdf *

This will output a merged PDF of all PDFs in the current directory. Alternatively, you can simply list them like so:

mergepdf 00.pdf 01.pdf 02.pdf ...

N.B. Passing a wildcard will merge all PDFs in the current directory in name order, e.g. 00.pdf 01.pdf aa.pdf ab.pdf

pdftk input1.pdf input2.pdf cat output output.pdf
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf ...
pdfimages -j foo.pdf bar
2011-07-07 17:18:36
User: lucasrangit
Tags: pdf jpeg
2

This will extract all DCT format images from foo.pdf and save them in JPEG format (option -j) to bar-000.jpg, bar-001.jpg, bar-002.jpg, etc.

Inspired by http://stefaanlippens.net/extract-images-from-pdf-documents

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.

curl -s http://example.com | grep -o -P "<a.*href.*>" | grep -o "http.*.pdf" | xargs -d"\n" -n1 wget -c
2011-06-09 14:42:46
User: b_t
Functions: grep wget xargs
0

This example command fetches 'example.com' webpage and then fetches+saves all PDF files listed (linked to) on that webpage.

[*Note: of course there are no PDFs on example.com. This is just an example]

gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sFONTPATH=%windir%/fonts;xfonts;. -sPDFPassword= -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -sOutputFile=OUTPUT.pdf INPUT.pdf
convert -compress jpeg *.jpg mydoc.pdf
pdftk A=odd.pdf B=even.pdf shuffle A1-end Bend-1S output duplex.pdf
2011-02-25 15:00:09
User: till
4

Joins two pdf documents coming from a simplex document feed scanner. Needs pdftk >1.44 w/ shuffle.

pdftk in.pdf cat 1S output out.pdf
convert -density 300x300 input.pdf output.png
2011-01-28 00:36:31
2

If you skip this part:

-density 300x300

you'll get a very lo-res image.

pdfnup --nup 2x1 --frame true --landscape --outfile output.pdf input.pdf
2010-12-21 14:20:06
User: TetsuyO
Functions: true
3

This is an example of the usage of pdfnup (you can find it in the 'pdfjam' package). With this command you can save ink/toner and paper (and thus trees!) when you print a pdf.

This tools are very configurable, and you can make also 2x2, 3x2, 2x3 layouts, and more (the limit is your fantasy and the resolution of the printer :-)

You must have installed pdfjam, pdflatex, and the LaTeX pdfpages package in your box.

man -t manpage | ps2pdf - filename.pdf
2010-12-19 22:40:18
User: TetsuyO
Functions: man
36

Quick and dirty version. I made a version that checks if a manpage exists (but it's not a oneliner). You must have ps2pdf and of course Ghostscript installed in your box.

Enhancements appreciated :-)