Best Web Hosting


COUPON CODE:  techpulpdeal



and get $9.94 off on all hosting plans

Search


There are hundreds of cool tips and tricks. Just search the site below.


Browse articles of 2010 | 2009 | 2008



How to define local links in a web page

August 18, 2010 By: Liz Category: HTML

The local links in a web page are called anchors.

To define an anchor in a HTML page, create a dummy “a” link as shown below.

<a id="chapter1"></a>

Create a link that user can click on to go to the previously defined anchor.

<a href="#chapter1">Chapter1</a>

Simple usage of sed command

August 17, 2010 By: Neo Category: Command Line, Unix

The following examples show you how sed command can be used as a powerful alternative to general commands like head, tail etc.

Let us consider the below input file for all the examples explained here.

[neo@techpulp ~]# cat input.txt
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
Line10
Line11
Line12
Line13
Line14
Line15
Line16
Line17
Line18
Line19
Line20
[neo@techpulp ~]#

Print all lines

[neo@techpulp ~]# sed -e ''  input.txt
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
Line10
Line11
Line12
Line13
Line14
Line15
Line16
Line17
Line18
Line19
Line20
[neo@techpulp ~]#

Do not print first 10 lines of input. Here “d” stands for deletion.

[neo@techpulp ~]# sed -e '1,10d' input.txt
Line11
Line12
Line13
Line14
Line15
Line16
Line17
Line18
Line19
Line20
[neo@techpulp ~]#

Print first ten lines of input

[neo@techpulp ~]# sed -e '1,10!d' input.txt
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
Line10
[neo@techpulp ~]#

Display only first five lines

Here “p” stand for print and “-n” options negates default behaviour of printing.

[neo@techpulp ~]# sed -n -e '1,5p' input.txt
Line1
Line2
Line3
Line4
Line5
[neo@techpulp ~]#

Display lines 1 to 5 and 10 to 12

[neo@techpulp ~]# sed -n -e '1,5p' -e '10,12p' input.txt
Line1
Line2
Line3
Line4
Line5
Line10
Line11
Line12
[neo@techpulp ~]#

Do the same with the expressions delimited by new lines

[neo@techpulp ~]# sed -n -e '1,5p
> 10,12p' input.txt
Line1
Line2
Line3
Line4
Line5
Line10
Line11
Line12
[neo@techpulp ~]#

Do not display 1 to 5 and 10 to 12

[neo@techpulp ~]# sed -e '1,5d' -e '10,12d' input.txt
Line6
Line7
Line8
Line9
Line13
Line14
Line15
Line16
Line17
Line18
Line19
Line20
[neo@techpulp ~]#

Delete all lines after 11

[neo@techpulp ~]# sed -e '11,$d' input.txt
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
Line10
[neo@techpulp ~]#

Print lines after 11

[neo@techpulp ~]# sed -n -e '11,$p' input.txt
Line11
Line12
Line13
Line14
Line15
Line16
Line17
Line18
Line19
Line20
[neo@techpulp ~]#

You can use !p or !d to negate the sed expression.

How to resolve xinetd startup errors in Linux

April 13, 2010 By: Neo Category: Administration

The best way to solve any service start up errors in Linux is to run them manually with debug mode on. The difficulty comes from finding exact command line arguments to be passed (as if it were started by Linux start up scripts) and also disabling default daemon mode for the server command. You can easily find the options to enable debug mode for the server by quickly looking at man page.

For example, you can use following command to run xinetd service in the foreground with debug on.

[root@techpulp ~]# /usr/sbin/xinetd -d -dontfork
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/chargen-dgram [file=/etc/xinetd.conf] [line=49]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/chargen-stream [file=/etc/xinetd.d/chargen-stream] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/cvs [file=/etc/xinetd.d/cvs] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/daytime-dgram [file=/etc/xinetd.d/daytime-dgram] [line=19]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/daytime-stream [file=/etc/xinetd.d/daytime-stream] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/discard-dgram [file=/etc/xinetd.d/discard-dgram] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/discard-stream [file=/etc/xinetd.d/discard-stream] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/echo-dgram [file=/etc/xinetd.d/echo-dgram] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/echo-stream [file=/etc/xinetd.d/echo-stream] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/rsync [file=/etc/xinetd.d/rsync] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/tcpmux-server [file=/etc/xinetd.d/tcpmux-server] [line=14]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/tftp [file=/etc/xinetd.d/tftp] [line=68]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/time-dgram [file=/etc/xinetd.d/time-dgram] [line=19]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/time-stream [file=/etc/xinetd.d/time-stream] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {handle_includedir} Reading included configuration file: /etc/xinetd.d/vmware-authd [file=/etc/xinetd.d/vmware-authd] [line=67]
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing chargen
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing chargen
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing cvspserver
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing daytime
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing daytime
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing discard
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing discard
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing echo
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing echo
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing rsync
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing tcpmux
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing tftp
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing time
10/4/13@00:34:14: DEBUG: 3657 {remove_disabled_services} removing time
Service defaults
Instances = 50
Groups = yes
umask = 2
CPS = max conn:50 wait:10
PER_SOURCE = 10
Bind = All addresses.
Only from: All sites
No access: No blocked sites
Logging to syslog. Facility = daemon, level = info
Log_on_success flags = HOST DURATION EXIT PID
Log_on_failure flags = HOST

Service configuration: vmware-authd
id = vmware-authd
flags = IPv6
type = UNLISTED
socket_type = stream
Protocol (name,number) = (tcp,6)
port = 904
wait = no
user = 0
Groups = yes
umask = 2
PER_SOURCE = 10
Bind = All addresses.
Server = /usr/sbin/vmware-authd
Server argv = vmware-authd
Only from: All sites
No access: No blocked sites
Logging to syslog. Facility = daemon, level = info
Log_on_success flags = HOST DURATION EXIT PID
Log_on_failure flags = HOST

10/4/13@00:34:14: DEBUG: 3657 {cnf_start_services} Started service: vmware-authd
10/4/13@00:34:14: DEBUG: 3657 {cnf_start_services} mask_max = 6, services_started = 1
10/4/13@00:34:14: NOTICE: 3657 {main} xinetd Version 2.3.14 started with libwrap loadavg labeled-networking options compiled in.
10/4/13@00:34:14: NOTICE: 3657 {main} Started working: 1 available service
10/4/13@00:34:14: DEBUG: 3657 {main_loop} active_services = 1
^C10/4/13@00:34:15: NOTICE: 3657 {general_handler} Unexpected signal 2 (Interrupt)
[root@techpulp ~]#

In the above case, I have pressed Ctrl+C to stop the process. However if you have a problem of starting xinetd service on your system, you should see some relevant error before process exits.

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 is 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
  • Best Ever Deal on Earth