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 using gs from sorted by
Terminal - Commands using gs - 19 results
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.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
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
1

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

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf ...
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf 1.pdf 2.pdf 3.pdf 4.pdf
2011-04-14 09:13:07
User: jakab922
Functions: gs
0

I found this on http://fixnum.org/blog/2007/concat_pdfs_with_ghostscript/ so it's not my creation, but I think it's very useful and a good addition to this codebase.

shopt -s nullglob; for i in $(find "Your/file/system" -name "*.pdf"); do e="$(dirname $i)/$(basename $i '.pdf').png"; gs -sDEVICE=png16m -q -dPDFFitPage -g492x380 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dNOSUBSTDEVICECOLORS -o $e $i; done
2010-12-17 13:30:54
Functions: find gs
0

Using ghostscript instead of imagemagick to convert pdfs into pngs. It keeps pngs with pdfs

for z in */*.pdf; do gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$z new" -c .setpdfwrite -f "$z" mv "$z new" "$z"; done
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH first.pdf second.pdf
gs -sDEVICE=pngalpha -sOutputFile=<filename>%d.png -r<resolution> <pdffile>
2010-03-30 09:51:10
User: angleto
Functions: gs
2

syntax for resolution is: (see "man gs" for further informations)

-rnumber

-rnumber1xnumber2

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=2 -sOutputFile=page2.pdf multipageinputfile.pdf
2010-02-10 08:48:48
User: drewbenn
Functions: gs
4

Have to do this once per output file, because if device is 'pdfwrite', even if 'gs' sees '%d' in the OutputFile it still only creates one single output file. Embed it into a simple shell script if you want to split a document out into one file for every page.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=p%03d.jpg file.pdf
2010-01-02 16:17:39
User: auriza
Functions: gs
2

Converting your PDF file to JPEG images. You can set resolution by -r option (default: 72dpi).

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
2009-12-14 21:30:22
User: deijmaster
Functions: gs
37

Remove security from PDF document using this very simple command on Linux and OSX. You need ghostscript for this baby to work.

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf c.pdf
2009-06-25 19:04:28
User: becomingGuru
Functions: gs
5

merge a.pdf b.pdf and c.pdf and create ./out.pdf

gs -sDEVICE=pswrite -sOutputFile=- -q -dNOPAUSE With-Fonts.pdf -c quit | ps2pdf - > No-Fonts.pdf
2009-03-25 03:46:00
User: qubyte
Functions: gs
1

It's sometimes useful to strip the embedded fonts from a pdf, for importing into something like Inkscape. Be warned, this will increase the size of a pdf substantially.

I tried this with only gs writing with -sDEVICE=pdfwrite but it doesn't seem to work, so I just pipe postscript output to ps2pdf for the same effect.

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf multipageproject.pdf
2009-03-24 17:14:46
User: iain
Functions: gs
3

Xsane produces PDFs that are too large - particularly multipage PDFs. This command compresses them. If you do not use A4, remove the -sPAPERSIZE flag.

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf `ls *.pdf`
2009-03-13 22:34:14
User: oops66
Functions: gs
12

Merge all pdf files in the directory into one pdf file (the out.pdf file)

gs -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -dEPSCrop -sOutputFile=out.eps in.pdf
2009-02-05 20:06:40
User: Boojum
Functions: gs
0

Use this to turn a page with snippets of equations into vector paths that Adobe Illustrator can handle without choking on font embedding and substitution issues. Good for keeping fonts consistent when labeling charts and diagrams. Also good for embedding formulas into diagrams.