command line

Gearman (job queue manager) command line tool: routing the workload to the worker process arguments with xargs

27 April, 2010 - 14:55

Abstract

Gearman provides a basic command line tool that helps to distribute work from clients to worker processes/machines. By default the worker process can only receive data from its standard input. With the xargs tool we can circumvent this and route data to the process arguments of the worker process.

Read more...

PDF to PostScript conversion: pdf2ps versus pdftops

5 February, 2010 - 12:16

Occasionally, I have to convert a PDF file to Postscript (e.g. for subsequent processing with some PostScript utility). In the Linux/command line area, I know two options: pdf2ps and pdftops. I also know that one of the two sucks has some issues and the other is better. But because their names are so close I can't manage to remember which one to take. This post should put an end to that!

[Spoiler alert and a questionable mnemonic: pdftops is da top.]

Read more...

My bashrc, bash aliases, profile and other files

19 October, 2009 - 15:30
Categories:

I spend a lot of time on the (bash) command line in (Linux and OS x) and it's always good for productivity to have your favorite set of shortcuts, aliases, perferences, predefined (environment) variables and such at your fingertips. You know, all the stuff that lives in .bashrc, .profile, .vimrc, .git, etc.

I have access to several systems (at home, at work, remote servers, etc) and from time to time I'm sitting behind a system that doesn't know my preferences yet. I considered using some sort of version control system to "synchronize" these preference files between my setups, but (apart from the practical hurdles) it generally seemed overkill, especially since each setup can have its own peculiarities and customizations.

So, mainly for my own reference, I'm keeping an list of the most important general stuff here. Be welcome to cherry-pick (or suggest additions).

Read more...

Showing the running command in a bash script with "set -x"

29 May, 2009 - 09:03

Bash scripts are handy for putting a bunch of longer running jobs in one batch. In some occasions it can be useful to know which command is running at the moment, especially when the commands do not generate output themselves or this output is redirected to files.

Bash has a simple setting to achieve this:

set -x

which, according to help set, enables the following feature:

-x Print commands and their arguments as they are executed.

Disabling it just takes a mere

set +x

You can play with it from the bash command line itself, or put it in a bash script of course.

Read more...

How to be a better grepper

28 April, 2009 - 17:37
Categories:

If you're not afraid of a a bit o' Unix/Linux/OSX command line delight, you're probably having grep hanging on your tool belt.

One option you'll wonder how you could live without is --color, which enables highlighting of the word or pattern you are grepping for. I find it so useful that I've put the following alias in my .bashrc:

alias grep='grep --color=auto'
Read more...

Blender: background rendering

23 May, 2008 - 10:24

Yesterday I had to render a 3d animation for a colleague working on 3D television. He needed a short street-view video with depth map. Because there were some problems with some real world footage he wanted to use, he asked me to create an artificial video in Blender. After I created a simple scene with some models from www.katorlegaz.com, I wanted to render the whole animation overnight on one of the computers in our lab. I had some trouble with getting the command line arguments right and wanted to share this, in case someone else has the same problem.

I first tried

blender -b -a foo.blend

the option -b is for background mode, so I could log out from the computer after I started the job, the options -a is for (according to the command line help):render frames from start to end (inclusive), only works when used after -b I thought this was the bare minimum to get the job done. However, nothing happened but this:

Compiled with Python version 2.5.
Checking for installed Python... got it!
ERROR: No camera
 
Blender quit

Huh, no camera? There was an active camera, the scene rendered just fine from the UI, I checked my file over and over and everything seemed all right.

Read more...

Extract images from a PDF document

27 January, 2008 - 20:06

When you want to extract a bitmap image from a PDF document, it is tempting to do the "print screen" trick. The drawback of this approach is that you'll inevitably lose quality: the image pixels will typically not map to your screen's pixels in a one to one fashion because of the decimation/resampling/scaling (or even rotation) when viewing the PDF document.

There are probably a lot of tools extract the bitmap image correctly out there. I guess this functionality is built in in Adobe Acrobat reader. But if you're in my situation (no desire to use Adobe's bloat) or you just need a small handy command line tool for linux (or other "unixes"): try pdfimages. It's part of the xpdf package, which is probably available for all major linux distributions.

Usage is very straightforward:

pdfimages -j foo.pdf  bar

This will extract all 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://www.boekhoff.info/?pid=linux&tip=extract-images-from-pdf-files

Completion for Gnuplot under Ubuntu(/Debian) with rlwrap

20 April, 2007 - 14:46

The default install of gnuplot in Ubuntu/Debian does offer a crippled form of word completion, when compared to other distribution (Mandrake, Suse). For example, filenames can not be completed with pressing tab, which can be really annoying if you're used to have this sort of completion. The reason for this is some licensing issue with the readline library. A workaround is to compile Gnuplot with the right tweaks, but this is to much hassle for what it's worth for me.

Another solution, which can also be applied to other applications, is rlwrap. It's just a simple sudo apt-get install rlwrap away (with uni/multiverse repositories enabled).

Now I have filename completion in gnuplot with:

rlwrap -a -c gnuplot

And if you're not so keen on remembering this, just add the following alias to your .bashrc:

alias gnuplot='rlwrap -a -c gnuplot'

Nice.

In-place string changing in files from the command line with "perl pie"

18 April, 2007 - 13:22

The standard unix/linux tools for filtering/changing strings (or patterns) in files from the commandline are sed and awk. But what if you want to change strings in-place in the files without the burden of creating new files and replacing the old ones afterwards?

The "perl pie" is a handy one-liner for these occasions:

perl -p -i -e 's/Jesus/Elvis/g' bible.txt

This will replace in file bible.txt all occurences of 'Jesus' with 'Elvis' in-place.

More info:

Accessing a svn server behind a firewall

5 February, 2007 - 17:37

Disclaimer: this entry is mainly a reminder to myself (the stuff you would write on a post-it), but maybe it's useful to someone else.

The subversion server at my work is (currently) only accessible from within the LAN, which is, of course, separated with a firewall from the evil internet. This makes it a bit difficult to access the subversion server when working from home. SSH Tunneling to the rescue!

To setup an SSH tunnel (on computer home):

ssh -l username -L 8910:svnserver:80 gateway cat -

This creates an SSH connection from computer home to computer gateway and opens a listening TCP-port 8910 on the the computer home. Connections to this port will be forwarded through the SSH tunnel to TCP-port 80 from computer svnserver (as seen from computer gateway).

Now we can access the svnserver as follows (on computer home):

svn co http://localhost:8910/svn/repository/path

In a nice diagram:

Graphics used in diagram from Tango icon gallery.

Read more...