Homepage of Peter Verthez

Linux Tips and Tricks

Some tips and tricks that I found while doing stuff in the Linux world...

(9 March 2008) [GPS] Using the Garmin MapSource application from Linux

On this page, I've described the steps I had to do to get the MapSource application from Garmin working under Linux, including communication to a Garmin Vista CX device.

(30 June 2007) [Fedora] Why does my incremental backup do a full backup?

Since a long time already, I'm performing weekly backups: one week a full backup, the next three weeks an incremental backup, and then again a full backup and so on. I'm using the "--listed-incremental" option of tar for that.

However, with Fedora Core 6 I found that this no longer worked: the incremental backup of my home directory was actually also doing a full backup instead. First I thought that it was the size of my home directory that did it: it got bigger and bigger due to the addition of digital photos received from family. Maybe there was some limitation in tar or so? But when I did an incremental backup directly (e.g. a few hours) after the full backup, it actually worked; it was only after a few days that it reverted to full backup.

Eventually I found that the culprit is Beagle! When I disabled Beagle, which I did in fact to stop it slowing down my system, the weekly incremental backup worked again! I don't know exactly how Beagle messes up the directories so that tar thinks they have changed, because I thought that tar looks at the modification time, which Beagle shouldn't touch... If somebody knows what's happening here, let me know...

Bottom line: Beagle messes up incremental backups (and also slows down your system like hell...). You can disable Beagle by going to the menu System/Preferences/Search and Indexing: Disable everything in that dialog box (note that this is per user).

(3 June 2007) [Shell] Extract RPM contents without installing it

If you want to look inside a binary or source RPM without installing it, you can extract its contents by converting it first to a CPIO archive, and then extracting that archive:

mkdir tmp rpm2cpio some.rpm > tmp/cpio.out cd tmp cat cpio.out | cpio -iv --quiet --make-directories rm cpio.out

(20 May 2007) [Shell] The 'watch' command

A very useful, but relatively unknown command is 'watch' (available in fairly recent Linux distributions).

If you want to follow the progress of a FTP command, the tedious way to do this is to run the 'ls' command manually from time to time to watch the size of the file. A bit more clever is the following kind of script, which does this automatically, with a sleep of 2 seconds in between:

while [ 1 ]; do ls -l myfile.tar sleep 2 done

However, the 'watch' command makes it much simpler. Just execute the following:

watch -n 2 ls -l myfile.tar

This will show the results of the execution in the terminal (fullscreen), and update that every 2 seconds. If you add the "-d" option, it will also highlight differences in the output between successive updates. See 'man watch' for full details about this command...

(13 May 2007) [Shell] Recursive grep

Nowadays, GNU grep has an option to search recursively into subdirectories (-r option), but older grep versions and grep versions on non-Linux platforms don't have this.

In case your grep doesn't support the '-r' option, then the following (bash) shell functions can be used instead:

grepr () { find . -follow -name "$2" -type f -exec grep -s "$1" {} /dev/null ";" } grepri () { find . -follow -name "$2" -type f -exec grep -s -i "$1" {} /dev/null ";" }

The first one is case sensitive, the second case insensitive. This can be used e.g. as follows:

grepr video '*.html'

Note the single quotes around the file argument. This is needed to pass it properly to the find function...

(6 May 2007) [Fedora] Why can't I run a program from a CD anymore?

If you're like me, and found that you could no longer run a shell script or program directly from a CD in Fedora Core 6: this is because Fedora has tightened the security on that (a little too much in this case according to me).

The fix is as follows. First of all, make sure that you have gconf-editor installed (the RPM is available on the Fedora Core 6 install CDs). Run it (as your normal user, not as root) and navigate to the following location in the tree:

/system/storage/default_options/iso9660

Select the "mount_options", and select "Edit key" from the context menu. Add the value "exec" in the list and press "OK". If you now unmount and mount your CD, you should be able to run programs again directly from CD...

(6 May 2007) [Perl] Is that module installed?

Sometimes you'd like to know whether a certain Perl module is installed (and even, sometimes, the version of it).

Here is a Perl one-liner that you can for instance put in a script called 'whereperl' that can tell you exactly that:

perl -e "use $1; (\$f = \"$1.pm\") =~ s|::|/|g;\ \$v = \$$1::VERSION || ''; print \"\$INC{\$f} \$v\n\";"

What this basically does, is try to "use" the Perl module, then retrieve its version (Module::VERSION), and its path ($INC{Module}). Then both are printed out, e.g.:

$ whereperl Data::Dumper /usr/lib/perl5/5.8.8/i386-linux-thread-multi/Data/Dumper.pm 2.121_08

If the module is not there, you will get an error saying that the module could not be found, and listing the full path in which the module was sought.

(5 May 2007) [Perl] A very simple Perl shell

In order to quickly try out Perl commands, you can use the debugger as a very simple Perl shell:

$ perl -d -e 42 Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 42 DB<1> print "This is a test" This is a test DB<2>

The -d argument starts the debugger, and the "-e 42" is just there so that the debugger has something to execute at first. As soon as this execution (i.e. evaluating the number 42) is finished, you get a prompt (here: DB<1>). There you can enter any Perl statement, including 'use' statements.

Just make sure that you don't define any 'my' variables, because those will only be visible within 1 statement on the debug prompt.

You can quit the debugger by typing the command 'p'. The interface is a bit rudimentary, and you can find better Perl shells on the web, but this one works wherever Perl is installed...

Downloads