merge pdf using bash brace exansion

pdftk pg_000{1..9}.pdf cat output MyFile.pdf
merge pdf from pg_0001.pdf until pg_0009.pdf into MyFile.pdf

By: eastwind
2012-08-27 08:57:00

These Might Interest You

  • it's nice to be able to use the command `ls program.{h,c,cpp}`. This expands to `ls program.h program.c program.cpp`. Note: This is a text expansion, not a shell wildcard type expansion that looks at matching file names to calculate the expansion. More details at I often run multiple commands (like apt-get) one after the other with different subcommands. Just for fun this wraps the whole thing into a single line that uses brace expansion.

    echo apt-get\ {update,-y\ upgrade}\ \&\& true | sudo bash
    alecthegeek · 2015-09-22 00:48:26 3
  • In order to create, let's say, 10 directories with a single process we can use the command: mkdir test{1,2,3,4,5,6,7,8,9,10} something extremely boring to type! Why not use seq? seq -s, 1 10 and use its output inside the curly braces? The obvious solution mkdir test{$(seq -s, 1 10)} is, unfortunately, too naive and doesn't work. The answer is the order of the shell expansions (feature of Bourne Shell, actually), where brace expansion happens before command substitution (according to Bash's manual). The solution is to put another level of substitution, using the powerful and mystic command eval. I found the trick in a similar problem in the post at

    eval "mkdir test{$(seq -s, 1 10)}"
    xakon · 2011-07-23 17:09:01 6
  • I don't know why anyone would use this, I was just messing around tonight and managed to start bash without using any letters and thought I would share. It's pretty simple, first it tries to execute "-" redirecting stderr to stdout which prints the error "bash: -: command not found" to standard output, then I try to execute "bash: -: command not found" which produces the output "bash: bash: -: command not found: command not found". lastly, (on the other side of the semicolon) I use the underscore environment variable which refers to the last command run ("bash: -: command not found") and take out everything after the first ":" character using brace expressions and your left with "bash" Show Sample Output

    "$(- 2>&1)";${_%%:*}
    LinuxMan · 2012-12-29 09:21:09 2
  • Will do the merge, but only apply changes to working copy and index; won't commit.

    git merge --no-commit --no-ff
    Pistos · 2009-02-09 18:59:26 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

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.


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: