Linux Blog

Bash Tips for more efficient terminal usage

Filed under: Linux for Newb's,Linux Software — TheLinuxBlog.com at 5:36 pm on Monday, November 23, 2009

Here are some tips for working in the shell that I use on a daily basis. These may be known to most veterans, please contribute your favorite shortcuts to the comments. But for the most part this is not for the uber leet Linux geek, this is for those new to the terminal.

TAB
– Gives you suggestions / completes stuff for you. Type a, Press it twice, it will make your life a lot easier.

ctrl+w
– Remove word behind cursor.

ctrl+u
– Undo / Erase everything from cursor to beginning of the line

!!
– Type out whatever you typed out last, can be combined with tools like sudo

alt+f
– Go forward to the end of the previous word

alt+b
– Move cursor back to the beginning of the previous word

ctrl+d
– You’re done? Press ctrl+d to logout. If you’re in a virtual terminal, it may also close the window.

ctrl+z
– Stop the current process. Say you run gvim, and then you want to spawn another process. Press ctrl+z, then type bg. Once you’re done with the “other” process, you may type fg to bring it back into the foreground.

Yum Messed Up

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 10:05 am on Monday, November 16, 2009

So, this morning, when I got to work and booted up, I noticed something was wrong. My machine was not running as usual. It turns out, packagekit was sitting there being a general pain. I just wanted to look busy, so I killed the process. Turns out that wasn’t such a good idea, since it didn’t finish doing whatever it was doing and caused an ugly error like this:

rpmdb: Thread/process 28373/3077981888 failed: Thread died in Berkeley DB library
error: db4 error(-30975) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 -  (-30975)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:
Error: rpmdb open failed
 
rpmdb: Thread/process 28373/3077981888 failed: Thread died in Berkeley DB library
error: db4 error(-30975) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 -  (-30975)

Naturally, I tried using rpm, do try and fix things, since it indicated something to do with a database I tried:

[owen@linuxblog ~]$ sudo rpm --justdb

rpm: –justdb may only be specified during package installation and erasure

[owen@linuxblog ~]$ sudo rpm --rebuilddb
rpmdb: Thread/process 28373/3077981888 failed: Thread died in Berkeley DB library
error: db4 error(-30975) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 -  (-30975)

Well, it turns out that those options don’t work, and the rebuilddb gave an error about the db4 being corrupt. Well, I decided to go into /var/lib/rpm as the other error had that directory and found the db4 files. Running db45_recover sounded like it might work, so I gave it a shot.

[owen@linuxblog rpm]$ db45_recover -h /var/lib/rpm/
db45_recover: unlink: /var/lib/rpm/__db.003: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.004: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.000: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.002: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.001: Permission denied
db45_recover: /var/lib/rpm/log.0000000001: log file unreadable: Permission denied
db45_recover: PANIC: Permission denied
db45_recover: DB_ENV->log_newfh: 1: DB_RUNRECOVERY: Fatal error, run database recovery
db45_recover: dbenv->close: DB_RUNRECOVERY: Fatal error, run database recovery

That’s right,you need to be root for this bad boy:

[owen@linuxblog rpm]$ sudo db45_recover -h /var/lib/rpm/

The above seemed to fix it for now. I guess next time I’ll think about it more before I start slaying processes on a Monday morning.

Thunderbird localmail Spool

Filed under: Linux Software — TheLinuxBlog.com at 1:13 pm on Friday, July 3, 2009

Thunderbird

I was in a bit of a bind the other day when I learned that an IMAP server I was using was going to dissapear. I wanted to backup all of my mail, but had too many messages hosted on the IMAP server to copy from one to another, so I decided I’d download them all locally first and then deal with them later. I used fetchmail to download all of my messages from the IMAP main folder to my local spool, and copied over all of the sub folders because I was in a rush and needed to copy them quickly.

Once they were in my local mail spool, I wanted to get them into Thunderbird, but learned that the option I had once used to read my localmail had gone. There used to be an option for it in the GUI, but somewhere along the line it got removed. After a bit of Googling, I found: http://lists.freebsd.org/pipermail/freebsd-questions/2003-December/027652.html

This worked for me, and should work for any one that wants to use Thunderbird to read local mail.

Basically, you add a new mail account in Thunderbird as usual, then close it. Get into your local profile directory by using

cd .thunderbird/[tab]
 
then
 
vi prefs.js

find your new mail server, with the bogus name and change the hostname to localhost, change your name to <yourusername>@localhost, the server type to movemail, and change the userName to your username. It should look something like the following:

user_pref("mail.server.server4.hostname", "localhost");
user_pref("mail.server.server4.name", "owen@localhost");
user_pref("mail.server.server4.type", "movemail");
user_pref("mail.server.server4.userName", "owen");

Once thats done, you can restart Thunderbird and fetch your mail as usual. From there you can do as you wish with your messages.

Excellent! My question really is why was the GUI option removed from Thunderbird? Whatever the answer this method still works, so if you need to, use it while you still can!

Impressed with the PostgreSQL Installer

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 10:48 am on Monday, April 27, 2009

Until today I had never installed PostgreSQL from the Binary provided at postgresql.org since it’s pretty much always in some form of repository provided by most distributions. Today, for the first time ever I installed it and have to say I’m very impressed with the installer. I some what shuddered as I saw a “install shield” type installer interface, as my past encounters with these have generally tended to not work out so well. What I noticed about the PostgreSQL installer though was different from the “install shield”, it was BitRock. BitRock is a cross platform installer for “Windows, Linux, OS X and more…” as this was my first experience with BitRock with a Linux machine I have to say it was a positive one. It allowed me to install PostgreSQL with some custom components pretty effortlessly. While most won’t need to do a custom installation as PostgreSQL will probably be in a repository, its handy to know that the installer works.

BitRock does not appear to have a completely free license but they do seem to give open source projects a “free copy.” Not sure how I feel about this, but I guess if they’re out to make money then it could work for them. Apparentely it doesn’t take much to please me on a mundane Monday morning, I’d have been perfectly fine with a tarball and manual configuration but the GUI has brightened up my day. Thanks BitRock! Does any one else have any encounters or shocking experience with installers? What about BitRock in general?

Super Tux Cart FTW

Filed under: Linux Software — TheLinuxBlog.com at 9:52 am on Wednesday, April 8, 2009

Super Tux Cart It has been a while since I’ve even thought about posting about a game and come to think of it, I don’t think I ever have. If I have not, then this would be a great first game to add here, and if I have we can forget about it because Super Tux Cart is so much more fun.

Super Tux Cart as you can imagine is a game similar to that of a particular game that is available for most of the Nintendo systems. Basically you ride around in a go cart racing either another computer, or up to three other players.

The Super Tux Cart team have added a bunch of features, maps and bug fixes since I last looked at it. A networked version is in the works so when thats done, if any one wants to have a tournament let me know. I’d love to race.

uCertify Linux+ CXK0-002 Exam Preparation Material

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 12:03 am on Monday, March 16, 2009

How many people have ever considered getting certified in the Linux field? I’m sure there are a lot since there are a number of certifications available, RHCE, LPI, Novel/Suse and CompTIA’s Linux+ to name a few. Now, think of the number of study materials and exam preparation available for each of those. The number can almost be overwhelming.

uCertify have study materials available for a number of certification vendors. The vendors that are of specific Linux interest are CompTIA and LPI. Today I’ll be giving you my perspective on the Linux+ study material. I have already sat and passed the Linux+ XK0-002 exam and with the new one coming out pretty soon (Feb 17th was the Beta release date) I would recommend you take it too.

The first thing I did after downloading the uCertify preparation material was try and install it on Linux using wine. It failed on installation, but it may be able to work with some configuration tweaking and file copying. No time for that though, if your studying for an exam you need to get on it and start. So install it in a virtual machine or on a Windows box to save time.
uCertify’s interface is very easy to navigate and is organized well, it also has a clean interface which is easy on the eyes – great for those late night study sessions. The CXK0-002 exam has ample practice tests and study material. There are a number of methods of studying for the exam including:
Flash Cards, Study Notes, Articles.

There is not a large amount of text explaining theories and concepts in great detail but the study notes and flash cards are great at refreshing your memory and helping you remember what’s on the exam. The practice tests and assessments are pretty good but can be tricky – just like the real exams. Remember they are not only designed to make you pass, they guarantee it!

Probably the biggest question I have when studying for a certification is
“Am I ready to take the Exam?”
Most times, I opt for “no” and do more studying. The uCertify preparation engine takes the guess work out by giving you “tracking” features. Basically these features allow you to track your past test scores and take the practice test. It will let you know when you’re ready.

Conclusion
All-in-all I think the uCertify preparation engine with the CXK0-002 material loaded is a good method of studying for the Linux+ exam, especially if you are familiar with the concepts and terminologies outlined in the exam objectives. If you are new to Linux and are looking for the best all inclusive study material out there, I don’t think that you would want to use this alone. I’d recommend reading a book or using video training aimed at bringing you up to speed in addition to a good preparation material. uCertify’s preparation can definitely fit the latter’s shoe’s.

Command Line Image Editing with ImageMagick

Filed under: Linux Software — TheLinuxBlog.com at 1:52 pm on Friday, February 13, 2009

Image Magick

Image editing is often considered a pitfall of the Linux desktop. When I was in school a number of years ago a Windows user (that later converted to the hipster OS X “better than thou” type) said to me:
“I don’t know why any one uses the command line anymore, it’s obsolete”
People often forget about the power of the command line. The command line may not be the best utility for everything but image editing is a shining example of how it can be used. I wouldn’t recommend trying to type a command that touches up your photos, but any operation that has to be repeated a number of times can be easily accomplished through a series of commands.

While there are many command line image editing tools available, this post focuses on the ImageMagick suite. While all of this can be read in the man page I aim to simplify and document for both myself and other casual ImageMagick users. By far the most valuable resource for ImageMagick is the online documentation.

Basically ImageMagick takes a number of parameters depending on the function you are to perform. Most commonly an input filename, an operation and an output filename. You can specify the same filename for both input and output in most cases, unless you are trying to keep the source image in its original form.

Here are some of my favourite and most used functions of imagemagick:

Resize an image
To resize an imagemagick is very simple. Using convert you specify the -resize option. You have several options when resizing, resize by width or height. You can also resize while adding a background color if your image has strange dimensions

Rotate an Image
Rotating an image is a snap, using convert with the source file -rotate <degrees> out file you can rotate by any number of degrees. 90, 180, 270 are most common, to change orientation but other angles may be used. Keep in mind that you may want to set a background color to do this.

Flipping an image
There are two ways to flip and image and they get sort of confusing. Imagemagick uses -flip for vertical images and -flop for horizontal flipping.

Quality
Adjusting the quality of an image is sometimes desirable for saving files to the web. Use -quality <0-100> (100 being the best) to adjust the quality

Working with GIFS
Gif’s can be edited or created by those patient enough to do so. The major think about working with gifs is the -coalese option. This takes each frame from the gif and makes it its own image. Be careful when using this as it will make Filename.gif Filename-1.gif, Filename-2.gif, Filename-3.gif and overwrite those files if they already exist. You can then work on each frame individually, or with a script and then join them back together.

Linux CD Ripping Utilities

Filed under: Linux Software — TheLinuxBlog.com at 12:33 am on Wednesday, January 21, 2009

CD Ripping with Linux doesn’t have to be the labor intensive task that it once was. No longer do we have the days of writing a hundred character command to rip a CD with the perfect options. Here are some utilities aimed at making your life of ripping your collection of CD’s to a digital format you can actually use.

First up for review is Grip. Grip is an gtk application that can play, rip and encode CD’s. It is really easy to use and is my CD ripping utility choice.

While the interface is not as pretty as it could be I guess its not hard to fool you that grip means business.

All you have to do to rip an entire CD is put it in, wait a couple of seconds and Bobs your uncle it found your track information from freedb.org. Next hop on over to the “Rip” tab and hit “Rip+Encode”. Since we didn’t select any tracks it should squawk and ask if you really wanted to try and rip no tracks, or if you just want to go ahead and rip the entire CD. I always hit entire CD and move along.

Before you get too excited and to a yum install grip and start ripping your entire collection keep in mind that you will have to install the dependencies (usually lame) and change the format under the “Config->Encode->Encoder” tab. This is not really a big deal and for your convenience grip will remember your settings. There are no sounds when a rip is finished (which can be frustrating either way,) but there it does eject your CDROM for you.

Goobox is next. Just as easy to install, just as easy to use and it’s also another gtk application. Goobox has a slightly more boring interface with less options. If your looking for a Gnome based CD ripper with a minimal interface this is the one to choose.

I think its about time for a KDE utility. KAudioCreator has an interface very similar to Goobox. You will first have to select an encoder from the “settings->encoder” tab. You can then pop a CD in and it works its magic just like the other CD rippers, well that is right after you hit the “Rip Selection” button which is the KDE gear.

Try them and let me know which one you like the best. GUI’s are nice but nothing can compare to a command line utility and this CD changing robot

Fedora 9 Thunderbird Update Fix

Filed under: Linux Software — TheLinuxBlog.com at 12:01 am on Wednesday, January 14, 2009

Fedora 9 Thunderbird
While updating a Fedora 9 installation I ran across an error. The error was with the Mozilla Thunderbird package that I use on a regular basis.
The error looked like this:

 Running Transaction
Updating       : thunderbird                                                                                                                                                  1/2
Error unpacking rpm package thunderbird-2.0.0.19-1.fc9.i386
error: unpacking of archive failed on file /usr/lib/thunderbird-2.0.0.19/dictionaries: cpio: rename

Obviously any fix that I implemented couldn’t loose my mail. The problem was with the dictionaries more specifically the /usr/lib/thunderbird-2.0.0.19/dictionaries file. The error is not very specific but lets us know its having trouble unpacking the archive and ends with cpio: rename. So here is what I did to solve the problem:

 cd /usr/lib/thunderbird-2.0.0.19/
sudo mv dictionaries dictionaries-old

Thunderbird data is stored in ~/.thunderbird it is advisable you make a backup of your mail if it is that important to you. I didn’t since this directory is a library directory and all of my mail can be downloaded again with imap. If you use pop you may want to consider doing a backup. After doing this it fixed Thunderbird and I’m all up to date. Horray!

Let me know if it worked for you and I’ll let you all know if there are any problems.

An rsync primer

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 12:55 am on Tuesday, January 13, 2009

An rsync Primer

rsync is a great tool used to copy or “sync” files locally or remotely. Having just lost a fair amount of important personal data its good to make the point that you can lose data if you use rsync, so make sure that you know what you are doing works before putting it into production.
“Whats so great about rsync?”
I hear you ask.

Well, there are many ways of copying data around, regular old cp, scp and rcp but what sets rsync apart is that it’s capable of syncing those files that have changed, or those that are missing. In other words, why do a full copy of all files, risking further corruption when only some have changed?
rsync also handles compression and verifies that the files were written correctly.
The syntax for rsync is fairly straightforward, those of you familiar with the rcp or scp should be easily able to relate to that of rsync.

The syntax for a local file copy is:

rsync [OPTION...] SRC... [DEST]

-avz is the option that I use most commonly.

-a for archive, -v for verbose and -z for compression. As lame as it may sound, I actually remember the syntax for this as “Alien Vs. Zeus.” Sounds stupid, but it actually works.

Since I do not normally sync directories locally, one of my hosts is usually remote. rsync is configured to use SSH by default, but rsh can be used if preferred. I stick with the default SSH for simplicity. The syntax is very similar to scp’s

To Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
 
To Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

If you like to back up all files matching a pattern the same syntax applies but you specify a pattern. An example is you could backup all .conf files from /etc (provided you have read access) to another host by doing the following:

rsync /etc/*.conf [USER@]HOST:DEST

If you do the above, I am assuming that you would also want to backup other configuration files within the /etc/ directory. Instinct tells you if you have read the man page to just use -r however you may want to just do a full backup as rsync with a pattern by default does not traverse into directories.

Compression is really a nice feature for transferring large amounts of data. To demonstrate the speed increases that the -z option gives my full /etc/ directory which is 48M. It took 0m12.671s with compression and 0m35.657s without. This was over wireless from a dual core 2GHz laptop to a 1.8GHz wired desktop, so your results may vary. Either way compression or no compression rsync is a handy utility that should be able to make your life of copying files around a little easier.

Throw a rave when you work too hard

Filed under: Linux Software — TheLinuxBlog.com at 7:36 pm on Wednesday, December 3, 2008

Workrave

Workrave is an awesome little utility that I just found out about almost a week ago now. Basically what it does is sits in your tray and bugs you when you should take breaks. Its really simple to use, and is in the Fedora repositories. Since, my Open SUSE laptop is at home and off, I can’t tell you if it is in there but my guess is that Debian / Ubuntu also have this package. Once you’ve got it installed by whatever means possible, run it. Its very easy to use, but I would advise setting up your defaults. If you don’t you’ll be taking a short rest break once every 3 minutes, which I find to be a bit excessive. You also get rest breaks, which advise you to stand up and walk around, and do stretches. It has some great statistics such as how many keystrokes you make, how many breaks you’ve taken. It also accounts for “natural” rest breaks, so if there is no activity on your computer, it thinks you are idle. Although I have not tried it there is network support for Workrave. Perhaps one day I will try it. If you spend a long time in front of the computer at home or work (like I’m doing today) then this may be the application for you, especially if you are trying to avoid doing work. getting fatigued. Talking of work, I had better get back to what I was doing; oh yea, taking a break.

« Previous PageNext Page »