Saturday, January 5, 2013

Archiving and Compressing Data

The tar Command

The tar command can be used to create (-c), extract (-x) and list (-t) contents of an archive. Here's a listing of the files we'll be working with:

$ ll
-rw------- 1 ejan ejan  331 Jan  5 18:57 FibonacciException.java
drwx------ 2 ejan ejan 4.0K Jan  5 18:57 handlers
drwx------ 2 ejan ejan 4.0K Jan  5 18:57 impl
-rw------- 1 ejan ejan  389 Jan  5 18:57 RabbitCounter.java
-rw------- 1 ejan ejan  168 Jan  5 18:57 ServiceConstants.java

Note: The ll command shown above is an alias in my ~/.bashrc file defined as alias ll='ls -lh'

Creating a Tarball

In order to create a tarball of the contents of the current directory, use the following command:

$ tar -cvf code.tar *
FibonacciException.java
handlers/
handlers/CorrelationIDHandler.java
handlers/handler-chain.xml
impl/
impl/RabbitCounter.java
RabbitCounter.java
ServiceConstants.java

The -v option is used to produce verbose output while the -f option specifies the name of the output file.

Extracting Contents of a Tarball

If we were to extract contents of this tarball, we would issue:

$ tar -xvf code.tar
FibonacciException.java
handlers/
handlers/CorrelationIDHandler.java
handlers/handler-chain.xml
impl/
impl/RabbitCounter.java
RabbitCounter.java
ServiceConstants.java

Listing Contents of a Tarball

Finally, in order to list contents of a tarball archive, we issue: 

$ tar -tvf code.tar
-rw------- ejan/ejan       331 2013-01-05 19:28 FibonacciException.java
drwx------ ejan/ejan         0 2013-01-05 19:28 handlers/
-rw------- ejan/ejan      2312 2013-01-05 19:28 handlers/CorrelationIDHandler.java
-rw------- ejan/ejan       303 2013-01-05 19:28 handlers/handler-chain.xml
drwx------ ejan/ejan         0 2013-01-05 19:28 impl/
-rw------- ejan/ejan      2397 2013-01-05 19:28 impl/RabbitCounter.java
-rw------- ejan/ejan       389 2013-01-05 19:28 RabbitCounter.java
-rw------- ejan/ejan       168 2013-01-05 19:28 ServiceConstants.java


Now that we can create, extract and list plain tarballs, let's discuss how to create compressed tarballs.

Compressing and Uncompressing Data

The tar command can work with many programs to produce compressed tarball. The most commonly used format is gzip. In order to use it, all we need is to issue the tar command as usual but with an additional option: -z. The -z option tells tar that it should produce a compressed archive using the gzip program.

The following commands will create a compressed tarball with contents of the current directory, extract the compressed archive and finally list its contents, just like the previous commands used to create plain tarballs. The output is mostly similar so there's no need to reproduce it here:

$ tar -cvzf code.tar.gz *
$ tar -xvzf code.tar.gz
$ tar -tvzf code.tar.gz

Similarly, tar can work with bzip2 archives as well. The only difference in the command would be that we'd pass a -j instead of -z:

$ tar -cvjf code.tar.bz2 *
$ tar -xvjf code.tar.bz2
$ tar -tvjf code.tar.bz2

Finally tar can work with other compression programs as well, such as lzop, by means of the --use-compress-program:

$ tar --use-compress-program=lzop -cvf code.tar.lzo *
$ tar --use-compress-program=lzop -tvf code.tar.lzo
$ tar --use-compress-program=lzop -xvf code.tar.lzo

After all this dojo, here's what the directory looks like:

$ ll
-rw-rw-r-- 1 ejan ejan  20K Jan  5 19:54 code.tar
-rw-rw-r-- 1 ejan ejan 2.1K Jan  5 19:55 code.tar.bz2
-rw-rw-r-- 1 ejan ejan 2.1K Jan  5 19:54 code.tar.gz
-rw-rw-r-- 1 ejan ejan 3.0K Jan  5 19:58 code.tar.lzo

Generally speaking, the bzip2 format will give you the best compression, followed by gzip, followed by lzop. Of course, a plain tarball won't save you any space as it's not compressed at all. 

It is worth noting that you can use these programs directly to compress or uncompress data without using the tar command. However, I prefer using the tar command since it's more like a 'One command to rule them all' command, though, admittedly, using the bzip2, gzip and lzop programs will give you the most flexibility. Feel free to use those programs directly when you need their power (like the capability to explicitly specify the desired compression level).

Manipulating Archives

Finally, there are a number of operations we can perform on a tarball, including:

joining an archive to another one:

$ tar -AF target-archiver source-archiver

remove files from an existing archive:

$ tar --delete RabbitCounter.java -f code.tar.bz2

and add files to an existing archive:

$ tar -ref RabbitCounter.java -f code.tar.gz

Happy tarring :)

Friday, May 25, 2012

Border-less LibreOffice Menus in Kubuntu (Ubuntu with KDE) -- Workaround

I recently installed Kubuntu 12.04 LTS on my ThinkPad W520 and am loving the experience. When I first opened LibreOffice Calc, however, I noticed that the menus didn't have any borders. As you can imagine, that was confusing as hell as the menus would blend with the application background, making it difficult to work with them.



When I did some research, I found out there were other users having the same issue and a bug was filed at Ubuntu Launchpad. Unfortunately the bug is marked Won't Fix since it's found to be an upstream issue. This essentially means that it will most probably be fixed by the upstream developers but I got an impression that's not going to happen anytime soon.

What to do now? Well, I thought to myself, it couldn't be that difficult -- all I want is an Office suite. I would be equally happy with OpenOffice.org instead of LibreOffice. So that's exactly what I did and, guess what, it worked. Not only did it work but I also ended up with LibreOffice since the Ubuntu OpenOffice.org packages are transitional packages pointing to LibreOffice.

So, at the end of the day, by doing what I've described below, I ended up with a LibreOffice installation that works flawlessly. I've also posted this solution as a comment on the referenced bug.

So here's how you do it...

1. Uninstall LibreOffice (I did a purge as shown below)

$ sudo apt-get --purge remove mozilla-libreoffice libreoffice*

2. Install OpenOffice (relax, that's a transitional package so you'll end up with LibreOffice only)

$ sudo apt-get install openoffice.org

That's it! Now when you open Calc or other LibreOffice programs, their menus should have normal look and the no-border issue should be gone.

Optionally, if you want to have additional UI styles available in LibreOffice, you can install the style packages as shown below:

$ sudo apt-get install openoffice.org-style-*

This will add a bunch of styles that you can choose from for your office programs from Tools | Options... menu and then navigating to the LibreOffice | View section.

Finally, if you prefer enabling opening LibreOffice documents directly in Firefox, you can install the mozilla-openoffice.org package:

$ sudo apt-get install mozilla-openoffice.org

At the end, here's how my Writer looks on my machine:


Hope this helps.

UPDATE: 5/26/12

OK, unfortunately there's one problem that you'll encounter after following what I've outlined in this post. Now, while the menus are perfect in how they look, sub-menus render on top of the parent menu itself (overlapping it). This issue doesn't affect all menus. In addition, when not running the program maximized, top-level menus render right-aligned in relation to the mouse-click (the norm is left-aligned).

I think this is not as annoying a problem as the no-border bug but still (the bug) needs to be fixed. I hope this bug gets fixed soon as it has a very high visibility.

Here's how it looks when sub-menus render on top of menus:


Cheers!

Sunday, July 19, 2009

Linux File System Hierarchy

Because everything in Linux is a file, you, as an administrator, are ultimately going to have to deal with files. This makes it very important to understand the Linux file system hierarchy. Most Unixes/Linuxes adhere to the Filesystem Hierarchy Standard which defines a universal/standard directory structure for a Linux/Unix operating system.

Here is a brief overview of the most commonly available directories on a standard Linux system and their purpose:

/bin = houses basic binaries like ls, cat, mv, date, kill, and ps etc.
/boot = houses boot and kernel-specific files.
/dev = houses device files.
/etc = houses host-specific configuration files.
/home = houses user-specific home directories.
/root = home directory of root user.
/lib = houses shared library files used by various programs.
/lost+found = contains files/directories that have gone corrupted, items referred to by bad inodes, lost file fragments and the likes.
/mnt = houses mount points for various removable devices like CD and Floppy.
/opt = houses add-on applications (StarOffice from Sun Microsystems, for example).
/proc = a virtual directory providing stats on file system, processor, and memory etc.
/sbin = houses system binaries (such as reboot, halt, route, and fdisk) accessible to root only.
/tmp = a location for storing temporary data.
/usr = houses applications that are accessible to ALL users on the system such as a Web browser and gzip.
/var = provides space for housing data that changes frequently such as print/mail jobs and log files.

Cheers!

Linux System Manuals

Linux manuals are typically stored in 9 structures -- man1 through man9. The manpath command shows the locations where manuals are located. Typically, manuals are stored under /usr/share/man.

Here is a brief description of what goes into each man structure:

man1 = user tools manuals
man2 = system calls manuals
man3 = c calls manuals
man4 = device driver manuals
man5 = configuration file manuals
man6 = game manuals
man7 = installation package manuals
man8 = system tools manuals
man9 = kernel manuals

The syntax of the command is:
# man


If a command is available in multiple manuals, you can specify which manual you want to look at by specifying the manual number like this:
# man [1-9]

Cheers!

Tuesday, January 1, 2008

Installing Broadcom Netlink Fast Ethernet Driver For Linux On Vostro 1400

After I bought my new Vostro 1400 Notebook a few months ago, I installed CentOS 5 (read RHEL 5) on it and have been dual-booting it with Microsoft Windows Vista ever since. One big issue with installation of CentOS on Vostro 1400 is that the Broadcom Netlink Fast Ethernet card is not detected (the Intel ipw3945 Wireless card is also not recognized but details on that in a future post).

Research suggests that if you're running the latest 2.6 kernel with the tg3 module installed, your device should be recognized and working. Things are not that simple, though. The issue is that the tg3 module installed with the kernel 2.6 is old and doesn't recognize the ethernet card. All you need to do is install the latest version of the module (3.81c as of this writing), reboot your box, and Voila!

Here are step by step instructions for installing the Broadcom Netlink Fast Ethernet card on a Vostro 1400 Notebook running CentOS 5 (or RHEL 5 for that matter):

Note: You must have Internet connectivity to follow some of the steps specified below.
  1. Fire up your browser and navigate to Broadcom Ethernet NIC NetLink Driver Downloads page. Download the driver titled Linux (tg3).
  2. Open a terminal, login as root using the su command, and navigate to the directory where you downloaded the driver archive linux-3.81c.zip (latest as of this post).
  3. Unzip the downloaded archive:
    # unzip linux-3.81c.zip
  4. Navigate to the directory just unzipped:
    # cd Server/Linux/Driver/.
  5. Untar the arvhice tg3-3.81c.tar.gz:
    # tar -xvzf tg3-3.81c.tar.gz
  6. Navigate to the untarred directory:
    # cd tg3-3.81c
  7. Make the kernel module:
    # make
  8. The make process should output various binaries including tg3.ko which is the kernel module we are interested in. So, install the module:
    # make install
  9. Update kernel module dependencies:
    # /sbin/depmod -a
  10. Finally, reboot your machine.
Once your machine reboots, the Broadcom Netlink Fast Ethernet card should be available for you to configure. Configure the card using ifconfig or the Network Configuration GUI tool available through the System > Administration > Network menu, and enjoy using your
Broadcom Netlink Fast Ethernet card under Linux on your Vostro 1400 box!

Saturday, December 8, 2007

A Day Out

Macrosoft's team working at Autoweb, which I am a key member of, went out on an all day event a week back. We ate lunch at Tawa Restaurant in Dearborn. After that we went to Henry Ford Museum. However, because we got so late, the museum was closed. So we went to Fairlane Shopping Mall where we did a bit of shopping. Then we watched the movie Beowulf in Star Theater. Finally, we had our dinner at China Town Restaurant.

That day it snowed very heavily; so much that on the way back to home I had to drive no more than 40 MPH while usually I do no less than 75 MPH!

Saturday, September 8, 2007

mplayer Skins Problem

On CentOS Linux (and may be others), the easiest way to enable mp3, rm, and other proprietary media support is to install mplayer (you'll need to have the rpmforge repo configured):

# yum install mplayer

I don't like the default skin though. So I installed the mplayer skins package:

# yum install mplayer-skins

After installing the skins package, I opened the mplayer skin browser and bang! No skin except the default one was available!! Research revealed that it's a small, but annoying, bug in the skins package which installs skins in a wrong directory. Check out details of this bug here.

Luckily, the resolution is very simple. All you need to do is execute this:

# cd /usr/share/mplayer/skins/
# ln -s ../Skin/* .


After executing these commands, restart mplayer, launch the skin browser and it should have a fairly long list of available skins listed. That's it!

Cheers.