Welcome

Welcome to TechPulp.com. Here you can find technical articles, examples, sample code snippets. We lay more emphasis on usage scenarios by giving practical examples. Please submit your comments, suggestions and requests for any new articles.

Did you know? You can also participate and start writing articles and publish here.



What is the best alternative to WinZip

January 18, 2010 By: Neo Category: Microsoft Windows

If you are tired of commerical software WinZip, The best free software alternative to WinZip is 7-zip.

In fact 7-zip is better than WinZip as it supports more formats like BZIP2, RPM etc along with its own format 7z.

7-zip in Windows

7-zip in Windows

The 7-zip can create archives of following formats.

  • 7z, ZIP, GZIP, BZIP2 and TAR

The 7-zip application can unzip following formats

  • 7z, ZIP, GZIP, BZIP2 and TAR
  • ARJ, CAB, CHM, CPIO, DEB, DMG, HFS, ISO, LZH, LZMA, MSI, NSIS, RAR, RPM, UDF, WIM, XAR and Z.

This best compatible with UNIX flavours as it supports the archives seen on UNIX systems like GZIP, TAR, BZIP2, Z, CPIO and RPM.

It can unzip RAR format which is seen on most downloading sites.

How to install VLC Media Player on Fedora

January 17, 2010 By: Neo Category: Fedora, Linux

Fedora doesn’t distribute VLC media player as part its core and updates. So you need download rpms from rpmfusion.org as shown below.

[root@techpulp ~]# rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
[root@techpulp ~]# yum install -y vlc
[root@techpulp ~]# yum install -y mozilla-vlc

Off the above, installing mozilla-vlc is optional as it installs a browser plug-in for Mozilla/Firefox Browser.

How to retain RPMs downloaded by yum

January 16, 2010 By: Mark Category: Fedora, Linux, RedHat

Generally yum deletes all RPMs it downloads right after installing them. If you want to save Internet bandwidth and have multiple systems to be updated, you can make yum to keep the RPMs it downloads.

The highlighted line in /etc/yum.conf file can be edited to enable yum keep the cache of RPMs.

[main]
cachedir=/var/cache/yum
#keepcache=0
keepcache=1
..

The “keepcache=1” tells yum to not remoe downloaded RPMs. But where are those downloaded RPMS? You can see “cachedir” line in /etc/yum.conf and that is the base directory where yum keeps the RPMs. In this case the cache directory is “/var/cache/yum“.

You can use “find” command as shown below to find the list of RPMs present in the cache.

[root@techpulp ~]# find /var/cache/yum -iname \*.rpm
/var/cache/yum/fedora/packages/libmp4v2-1.5.0.1-6.fc10.i386.rpm
/var/cache/yum/fedora/packages/pyxdg-0.16-1.fc10.noarch.rpm
/var/cache/yum/fedora/packages/libfreebob-1.0.11-3.fc10.i386.rpm
/var/cache/yum/fedora/packages/wildmidi-libs-0.2.2-5.fc10.i386.rpm
/var/cache/yum/fedora/packages/freeglut-2.4.0-14.fc9.i386.rpm
[root@techpulp ~]#

If you want to install exactly same set of RPMs in another and similar PC, you can create a tarball as shown below and transfer the tarball to another system.

[root@techpulp ~]# find /var/cache/yum -iname \*.rpm | xargs tar -zcvf delta-rpms.tgz 
/var/cache/yum/fedora/packages/libmp4v2-1.5.0.1-6.fc10.i386.rpm
/var/cache/yum/fedora/packages/pyxdg-0.16-1.fc10.noarch.rpm
/var/cache/yum/fedora/packages/libfreebob-1.0.11-3.fc10.i386.rpm
/var/cache/yum/fedora/packages/wildmidi-libs-0.2.2-5.fc10.i386.rpm
/var/cache/yum/fedora/packages/freeglut-2.4.0-14.fc9.i386.rpm
[root@techpulp ~]#

The above command generates delta-rpms.tgz which should be transferred to new system and in the new system, you can use following method to install all the RPMs at once.

[root@newsys ~]# mkdir Temp
[root@newsys ~]# cd Temp
[root@newsys ~]# tar -zxvf ~/delta-rpms.tgz
[root@newsys ~]# find . -iname \*.rpm | xargs rpm -i --nodeps
[root@newsys ~]#

How to free cached memory and dirty pages in Linux

January 15, 2010 By: Liz Category: Embedded, Kernel

When an application reads a file, Linux kernel keeps cache of file contents in memory. The Linux keeps the cache even after application closes the file to improve performance for further read operations of same file. This cache is freed slowly as when Linux finds no free memory during it operation.

Similarly when an application write a file, Linux doesn’t write the contents to disk immediately and waits for some time before it actually writes to the disk. These buffers are called dirty buffers.

User can manually initiate the writing of dirty buffers to disk executing “sync” command few times.

From kernel version 2.6.16 onwards, Linux provided a PROC based mechanism to free up such cached memory. Linux provides a file /proc/sys/vm/drop_caches which can be written with a number to free up cached memory.

To free page cache:

[root@techpulp ~]# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

[root@techpulp ~]# echo 2 > /proc/sys/vm/drop_caches

To free page cache, dentries and inodes:

[root@techpulp ~]# echo 3 > /proc/sys/vm/drop_caches

This can be combined with “sync” command to fully free up diretry buffers.

This behaviour does not necessarily slow the system as Linux frees up such memory on demand. It should not really make much difference for a desktop user. However in case of embedded systems, it takes most of the memory present in the system as there would be lot of files read during system boot up. This also causes memory fragmentation as Linux frees up this memory on demand. In such cases, Linux fails to allocate relatively big chunks of contiguous memory though it shows enough free memory. One way to get rid of such problem is to free up the page cache right after the system comes up. However if the applications running the embedded device are not properly designed and allocates and frees small chunks of memory more frequently, memory fragmentation is inevitable.

For Linux 2.4.x kernels, Linux has an internal function “free_more_memory” which can be called multiple times to achieve similar effect. However that function is not exported by Linux kernel. So kernel needs to be recompiled.

Bash brace expansion to expand arguments

August 01, 2009 By: Neo Category: Bash

Braces can be used to expand arguments in bash. Bash expands a list of strings separated by commas with in braces to a list of strings separated by spaces. Look at the simple example below:

[neo@techpulp ~]# echo {red,green,white}
red green white
[neo@techpulp ~]#

The above example may not be really useful but you can use bash to expand the arguments by adding prefix or suffix to the braces as shown below to generate expanded arguments. Note that there should not be any space between suffix/prefix and the start/end bracket. Otherwise it is considered as a separate list.

[neo@techpulp ~]# echo {red,green,white}ball
redball greenball whiteball
[neo@techpulp ~]#

Similarly you can add a prefix to the list of strings present in the braces.

[neo@techpulp ~]# echo light{red,green,white}
lightred lightgreen lightwhite
[neo@techpulp ~]#

You can add prefix and suffix together as well.

[neo@techpulp ~]# echo light{red,green,white}ball
lightredball lightgreenball lightwhiteball
[neo@techpulp ~]#

You can have two separate list of strings present in two braces attached together as shown below. You can see bash generating all possible permutations.

[neo@techpulp ~]# echo {ball,cat,rat}{red,green,white}
ballred ballgreen ballwhite catred catgreen catwhite ratred ratgreen ratwhite
[neo@techpulp ~]#

Now you may be wondering where this trick can be used in day to day work. Here is a list of examples:

Take backup of a file:

[neo@techpulp ~]# ls
exmaple.c
[neo@techpulp ~]# cp exmaple.c{,.bak}
[neo@techpulp ~]# ls
exmaple.c  exmaple.c.bak
[neo@techpulp ~]#

Check the differences between two files.

[neo@techpulp ~]# ls
exmaple.c  exmaple.c.org
[neo@techpulp ~]# diff exmaple.c{,.org}
14a15
>       printf("i = %d\n", i);
[neo@techpulp ~]#

How to run multiple commands at once in bash shell

June 24, 2009 By: Liz Category: Bash, Command Line, Unix

All commands can be just appended using a semicolon (;) to make the bash to run all the commands one after the other as shown below.

[liz@techpulp ~]# make config; make; make release

The above command is equivalent to running three commands “make config”, “make” and “make release” one after the other. The only difference is that you don’t need wait for one command to finish to type in the next command.

However if you have a series of dependant commands that require the previous command to succeed to execute the next command, you can change the command as shown below.

[liz@techpulp ~]# make config && make && make release

In the above example, all commands are appended with “&&” operator which makes the bash to execute further commands if any command returns non-zero value. It means that if “make config” command is successful without any errors, then only bash proceeds with executing next command “make”. Otherwise it aborts further execution.

Typing too long commands is boring especially when they have to be repeated many a times. In such cases you can create a small shell script or use an alias to make your life easy.

How to solve ‘Stale NFS file handle’ error while accessing or unmounting a NFS volume

May 14, 2009 By: Neo Category: Linux, Networking

This error is typically seen in a system which has active NFS mount point. The NFS protocol doesn’t define any automatic way of communication for any change of NFS server configuration. For example, if a client system mounts an NFS volume and the Administrator at the NFS server removes the directory from the NFS exported list, The client system will not know the change of configuration at NFS server side. In such cases, the ‘df’ command starts showing this error ‘Stale NFS file handle’.

As your system is NFS client, you can unmount the previously mounted NFS volume using ‘-f‘ option which does forceful unmounting of the volume. Of course, the “-f” is intended for NFS mounted volumes but not for other volumes like partitions of local hard drive.

For example, your NFS mount point is “/nfsdir”, the error you would notice will be as follows:

[root@techpulp /]# ls -l
total 154
drwxr-xr-x   2 root   root    4096 2009-02-10 12:58 bin
drwxr-xr-x   5 root   root    1024 2009-05-08 15:33 boot
drwxr-xr-x  15 root   root    4760 2009-05-13 10:37 dev
drwxr-xr-x 139 root   root   12288 2009-05-13 10:37 etc
drwxr-xr-x   5 root   root    4096 2009-03-06 14:59 home
drwxr-xr-x  17 root   root   12288 2009-03-04 17:36 lib
drwx------   2 root   root   16384 2009-01-06 16:26 lost+found
drwxr-xr-x   2 root   root    4096 2009-05-13 10:09 media
drwxr-xr-x   2 root   root    4096 2008-09-06 15:43 mnt
drwxr-xr-x   5 root   root    4096 2009-05-13 10:09 opt
dr-xr-xr-x 231 root   root       0 2009-05-08 15:38 proc
drwxr-x---  24 root   root    4096 2009-05-13 15:32 root
drwxr-xr-x   2 root   root   12288 2009-02-10 12:58 sbin
drwxr-xr-x   2 root   root    4096 2009-01-06 16:30 selinux
drwxrwxrwt  37 root   root    4096 2009-05-14 09:54 tmp
drwxr-xr-x  13 root   root    4096 2009-01-06 16:35 usr
drwxr-xr-x  24 root   root    4096 2009-01-06 16:51 var
ls: cannot access nfsdir: Stale NFS file handle
[root@techpulp /]#

Now you can just unmount the NFS volume using “-f” command.

[root@techpulp /]# umount -f /nfsdir
umount.nfs: Server failed to unmount '192.168.45.67:/nfsdir'
[root@techpulp /]#

You can attempt to mount the NFS volume again if you are sure that it is mountable:

[root@techpulp /]# mount 192.168.45.67:/nfsdir /nfsdir -t nfs

How to change the order of network card detection in Linux

May 14, 2009 By: Neo Category: Linux

There are multiple issues you would notice when you have more than one Ethernet card (NIC) in your system. The NICs may not get detected in the order you want it to be. The on-board Ethernet port may get detected as “eth2″ while you want it to be detected as “eth0″.

Another problem is when you already have 3 Ethernet cards on your system and removed one them (more specifically the one which used to be detected as “eth1″). In such case, you system shows two Ethernet interfaces “eth0″ and “eth2″ while you might like it to be “eth0″ and “eth1″ as there are only two Ethernet interface available in the system.

Another problem is when you have replaced an old 100Mbps NIC with a new 1Gig NIC. Now the system attempts to apply the configuration (including hardware MAC address) to the new 1Gig NIC. One solution to this problem is to do the card replacement in two steps. First remove the old NIC and boot the system once to remove the old NIC from the hardware list using ‘Network Device Control’ or when kudzu prompts for it. The shut down the system and insert the new 1Gig NIC and boot the system again to add the new hardware.

In all these cases, especially in modern Linux distributions like Fedora, you should find the hardware detection rules defined by “udev”. There is a file “/etc/udev/rules.d/70-persistent-net.rules” which contains the list of interfaces and their names (eth0, eth1 etc). You can edit this file to change the name (eth0, eth1 etc) with which a card should be detected. Look at the following sample file.

[root@techpulp ~]# cat /etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:07:e9:23:d7:c3", ATTR{type}=="1", KERNEL=="eth*",
NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:07:e9:23:d7:f4", ATTR{type}=="1", KERNEL=="eth*",
NAME="eth1"

# Intel Corporation 82562ET/EZ/GT/GZ - PRO/100 VE (LOM) Ethernet Controller
# (rule written by anaconda)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:83:36:a5:3d:81", ATTR{type}=="1", KERNEL=="eth*",
NAME="eth2"
[root@techpulp ~]#

In the above example, the system has one on-board 100Mbps NIC and two 1Gig NICs connected using PCI. You can identify them using the hardware address as well. You can edit this file and modify the “NAME” field to change the order.

How to export a NFS volume in Fedora or RedHat Linux

May 09, 2009 By: Neo Category: Fedora, Networking, RedHat

NFS stands for Network File System and is a easy way to share files across Linux systems. However the downside of NFS file sharing is that shared folder can’t be protected with a password. But you can limit access to particular IP addresses.

The Fedora Linux system comes up with NFS utilities by default. Otherwise you can install them using “yum” as shown below:

[root@techpulp ~]# yum install -y nfs-utils rpcbind

You can enable the NFS service to start at boot time using the following commands. The “rpcbind” service also needs to be enabled as NFS internally using RPC service. But if you are trying on RedHat9, you won’t find “rpcbind” service and enabling NFS service is good enough.

[root@techpulp ~]# chkconfig --level=35 rpcbind on
[root@techpulp ~]# chkconfig --level=35 nfs on

To export a directory using NFS, you need to place an entry in “/etc/exports” file. For example, adding the following line in /etc/exports file exports a directory named “/mypub” with read-only mode.

/mypub            *(ro,sync)

The “*” in the above line indicates that anybody can access this directory. You can limit access to a specific client by replacing “*” with IP address of the client system as shown below. The following entry allows access to the client system with IP address 192.168.1.1.

/mypub             192.168.1.1(ro,sync)

You can replace “ro” with “rw” if you want to client to have write access to this directory.

On the client system, you can mount the NFS directory using “mount” command. Assuming that the IP address of NFS server is 192.168.8.8, the following command run in the client system mounts the NFS exported volume in “/myimport” directory.

[root@client ~]# mount 192.168.8.8:/mypub /myimport -t nfs

This example explains basic usage of “/etc/exports” file on NFS server. However you can use “man exports” to find more options that can be used while exporting a NFS volume. Such options include allowing access to single NFS exported volume to multiple clients with different access permissions, allowing access to IP subnets, allowing access based on fully qualified domain names etc.

/               master(rw) trusty(rw,no_root_squash)
/projects       proj*.local.domain(rw)
/usr            *.local.domain(ro) @trusted(rw)
/home/neo       neo.techpulp.com(rw,all_squash,anonuid=500,anongid=500)
/pub            (ro,insecure,all_squash)
/srv/www        -sync,rw server @trusted @external(ro)

Fedora 11 (LEONIDAS) gets ready to hit the road by end of May

May 08, 2009 By: Neo Category: Fedora

The upcoming Fedora 11 release, named Leonidas, is scheduled to be released towards end of May. This release comes up with all latest versions of desktops like KDE, GNOME, XFCE and popular applications like Firefox, OpenOffice.org etc. The following are the notable features in this release.

  • EXT4 as default file system
  • KDE 4.2, GNOME 2.26, Xfce 4.6, OpenOffice.org 3.1.0, Firefox 3.1, Thunderbord 3
  • Improvement in time taken for start up and shut down (20 sec start up)
  • Simplified volume control
  • Native Windows cross compiler