April 25, 2008

Patch Your Linux Kernel and Apply Code Without Rebooting

KSplice from MIT allows you to apply security patches to your running Linux kernel without rebooting. This is great news for organizations that can not reboot their systems. KSplice would primarily be used to apply security updates as it is limited to making code changes that do not introduce semantic changes to data structures. Therefore, KSplice is best used to apply security updates that fix "off by one" and similar style exploits.

Check out the project at http://web.mit.edu/ksplice

David
http://tributetogrr.blogspot.com

April 16, 2008

Multiple Ways to Delete Blank Lines From a Text File

You have a text file that has a bunch of blank lines in it. You want to do some operation on that text file but first want to delete the blank lines. You could open the file in vi and manually delete them all but that isn't the Unix way. Here are a number of easy ways to delete blank lines.

If you already have the text file open in vi/vim, the following will delete all blank lines while in command mode:
:g/^$/d

Here are a few different options from the shell using standard GNU tools:

GNU awk
awk '/./' filename
awk 'NF > 0' filename
Warning: This will delete all blank lines AND lines containing only whitespace

GNU sed
sed -i '/^$/d' filename
This makes use of the regular expression ^$ representing blank lines. The -i flag tells sed to edit the file in place. If you want to preserve the original file, simple remove the -i and redirect the output to a new file:
sed '/^$/d' filename > newfilename
GNU grep
grep -v '^$' filename > newfilename
This is the same as sed with the use of the regex ^$

Of course there are many other ways to accomplish this task. That is the beauty of Unix.

April 11, 2008

Display the Contents of an RPM or Tar Archive

An RPM is just an archive of files. I believe that all of the various archiving programs (tar, cpio, etc.) provide you with a way to list the contents of their archives. An RPM is no different. You need to figure out if foo.rpm provides libfoo.so. Making use of the rpm2cpio, cpio, and grep programs, we can do just this:

unix% rpm2cpio foo.rpm | cpio -t | grep "libfoo.so"
/usr/lib/libfoo.so.2
unix%

Conversely, you can display the contents of a tar archive in one step:
unix% tar -tvf foo.tar
foo/
foo/bar.txt
foo/bills
foo/private/
foo/private/tax-return.pdf
unix%

Neither of these steps will actually extract files from the archive.

Being a diehard Debian user, it feels weird to write my first post about an RPM tip. By day, I admin a large number of Suse servers for a financial company. For me, there is no escaping the dreaded RPM.

Unix questions are always welcome.
Send questions to unix@tributetogrr.blogspot.com