Stupid tar Tricks


One of the most common programs on Linux systems for packaging files is the venerable tar. tar is short for tape archive, and originally, it would archive your files to a tape device. Now, you’re more likely to use a file to make your archive. To use a tarfile, use the command-line option -f . To create a new tarfile, use the command-line option -c. To extract files from a tarfile, use the option -x. You also can compress the resulting tarfile via two methods. To use bzip2, use the -j option, or for gzip, use the -z option.

Instead of using a tarfile, you can output your tarfile to stdout or input your tarfile from stdin by using a hyphen (-). With these options, you can tar up a directory and all of its subdirectories by using:

tar cf archive.tar dir

Then, extract it in another directory with:

tar xf archive.tar

When creating a tarfile, you can assign a volume name with the option -V . You can move an entire directory structure with tar by executing:

tar cf - dir1 | (cd dir2; tar xf -)

You can go even farther and move an entire directory structure over the network by executing:

tar cf - dir1 | ssh remote_host "( cd /path/to/dir2; tar xf - )"

GNU tar includes an option that lets you skip the cd part, -C /path/to/dest. You also can interact with tarfiles over the network by including a host part to the tarfile name. For example:

tar cvf username@remotehost:/path/to/dest/archive.tar dir1

This is done by using rsh as the communication mechanism. If you want to use something else, like ssh, use the command-line option –rsh-command CMD. Sometimes, you also may need to give the path to the rmt executable on the remote host. On some hosts, it won’t be in the default location /usr/sbin/rmt. So, all together, this would look like:

tar -c -v --rsh-command ssh --rmt-command /sbin/rmt -f username@host:/path/to/dest/archive.tar dir1

Although tar originally used to write its archive to a tape drive, it can be used to write to any device. For example, if you want to get a dump of your current filesystem to a secondary hard drive, use:

tar -cvzf /dev/hdd /

Of course, you need to run the above command as root. If you are writing your tarfile to a device that is too small, you can tell tar to do a multivolume archive with the -M option. For those of you who are old enough to remember floppy disks, you can back up your home directory to a series of floppy disks by executing:

tar -cvMf /dev/fd0 $HOME

If you are doing backups, you may want to preserve the file permissions. You can do this with the -p option. If you have symlinked files on your filesystem, you can dereference the symlinks with the -h option. This tells tar actually to dump the file that the symlink points to, not just the symlink.

Along the same lines, if you have several filesystems mounted, you can tell tar to stick to only one filesystem with the option -l. Hopefully, this gives you lots of ideas for ways to archive your files.

Install sar, sadf, mpstat, iostat, pidstat and sa tools on CentOS / Fedora / RHEL


How to install sar, sadf, mpstat, iostat, pidstat and sa tools on CentOS / Fedora / RHEL

The following command can be used to install sar, sadf, mpstat, iostat, pidstat and sa tools on RPM based systems like CentOS, Fedora, RHEL (Red Hat Enterprise Linux):

As root type the followiung command (on console / terminal):

yum -y install sysstat

When you are not root but have sudo configured for your account then use:

sudo yum -y install sysstat

This installs the sysstat tools which contains the above mentioned utilities.

iostat is an essential utility to fnd out about IO load on your system and ways to combat it.


CLIcompanion lets you run Terminal commands from a GUI. You can also store commands to create a command ‘dictionary’.

CLIcompanion is an application that is used as a compliment to the Terminal. People unfamiliar with the Terminal will find CLIcompanion a useful way to become acquainted with the Terminal. Using the built-in commands new users can unlock the potential of the Terminal. Experienced users can use CLIcompanion’s add command feature to build a command dictionary. Store commands as you come across them and no more do you have to search for them.

If you are new to the command line or working to improve your overall skill, this app may be of some assistance to you…

Download it here… (.deb)

Install Iftop


Iftop is a niffty little tool to help in helping to monitor Network Bandwith. Similar to top, it display the local and external host(s) that are responsible for the most traffic activities.

There are some basic requirement first. Make sure you install

1. libpcap and libpcap-devel
2. ncurses and ncurses-devel

To install iftop you need to have EPEL repository configured first. To enable EPEL for CentOS 5 For 32-bits

rpm -Uvh

and for 64-bits

rpm -Uvh

To enable EPEL for CentOS 4 for 32-bits


and for 64-bits


now begin to install iftop

yum install iftop

To run iftop, simply run

iftop -i eth0

For iftop options, visit

Update clam 96.2-2 on centOS

Go to and download the latest version of

  • clamav
  • clamd
  • clamav-db

for Red Hat EL 5


To install them all type in
yum localinstall clamav-xxx.rpm clamd-xxx.rpm clamav-db-xxx.rpm
or the simpler
yum --nogpgcheck localinstall *.rpm
if the current directory only contains clamav rpms. Make sure the version number is the same for all three files, otherwise you’ll get dependency errors and it won’t install.

Once the install is complete, run
freshclam to update the diffs, then
clamd -V
/usr/sbin/clamd -V
to double check the version info and then
clamscan -ir --log=/root/clamscan.log /home*/*/public_html & to scan your home directory and dump the results to a file for later review



Bmon – Real time Bandwidth monitoring tool

bmon is a portable bandwidth monitor and rate estimator. It supports various input methods for different architectures. Various output modes exist, including an interactive curses interface, lightweight HTML output, and simple ASCII output. Statistics may be distributed over a network using multicast or unicast and collected at some point to generate a summary of statistics for a set of nodes.

Install bmon

For Ubuntu or Debian systems, either click this link or run the following command in a terminal
sudo apt-get install bmon

Using bmon:
Open a terminal and enter the command “bmon” and you should see the following output


Vnstat is the other alternate to bmon – here

Remote Connect to MySQL server


How to Allow MySQL Client to Connect to Remote MySQL server
By default, MySQL does not allow remote clients to connect to the MySQL database. If you try to connect to a remote MySQL database from your client system, you will get “ERROR 1130: Host is not allowed to connect to this MySQL server” message as shown below.

$ mysql -h -u root -p
Enter password:
ERROR 1130: Host '' is not allowed to connect to this MySQL server

You can also validate this by doing telnet to 3306 mysql port as shown below, which will also give the same “host is not allowed to connect to this mysql server” error message as shown below.

$ telnet 3306
host is not allowed to connect to this mysql server

If you want to allow a specific client ip-address (for example: to access the mysql database running on a server, you should execute the following command on the server that is running the mysql database.

$ mysql -u root -p
Enter password:

mysql> use mysql

mysql> GRANT ALL ON *.* to root@'' IDENTIFIED BY 'your-root-password';


Also, update firewall rules to make sure port# 3306 is open on the server that is running the mysql database. After the above changes, when you try to connect to the mysql database from a remote client, you’ll not get the “Host is not allowed to connect to this MySQL server” error message anymore.

Multiple server alias


How do I point “” at “” or vice-versa?

You may have your webserver setup for either or just and you want it to work either way, whether people type in the “www” part of your domain or not. (By way of info, “www” is purely a convention, it isn’t in itself necessary to “make your domain work” over the web).

There are a couple ways to do this:

Setup a host record or A record for the root domain. Then create a CNAME record or alias which points at this host record.

In a bind style zone file you would put this: IN A IN CNAME

Take special care to make the root domain the host/A record and the “www” hostname the alias/CNAME. If you do it the other way around, more often than not, you will cause your zone to fail with errors because under most circumstances, the root of your zone cannot itself be an alias/CNAME.

Alternatively, you could simply setup a host record for each record, both pointing to the IP address: IN A IN A

The first method has a slight advantage in that you only need to change one record if the IP address of your webserver changes. If you are using an outsourced DNS host to do this, the interface usually calls the A records “hosts” and the CNAME records “aliases”. Often people get this far and then their website loads fine under one method (say, but they get unexpected results from the other, such as an error “No website configured at this address” or getting some other website entirely. This is because you still need to tell your webserver to respond to both hostnames.

When a user accesses a website in her browser, the browser sends a header setting an environment variable called HTTP_HOST, and webservers key off of this value to decide which local “webhost” or “virtualhost” to load (this is how web hosting companies can host thousands of websites on a single IP address.) In our example, we’re using the apache webserver, and you need to specify in your “VirtualHost” directive that the website needs t respond to requests from both and, you do this with a “ServerAlias” statement:


ServerAlias *

# other stuff

You can add multiple entries per ServerAlias line, in our example above we have added a “wildcard” entry for, if you setup a wildcard DNS entry in the zonefile, this webserver would load properly for You could also enter multiple ServerAlias lines, if you wanted your website to respond on another domain name as well.

Install nginx


How to Install nginx on cPanel (CentOS/RedHat Enterprise)

nginx can be used to serve static pages on a server running cPanel with Apache. Apache will handle the dynamic content for PHP and cgi scripts, while nginx will handle the static pages such as .htm and .html

This guide will be using the installer provided in this forum thread

Install nginx

1. Make a copy of your httpd.conf file

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak100421

2. Go to WHM > Tweak Settings and change the Apache port:

The port on which Apache listens for HTTP connections. Specifying a specific IP will prevent Apache from listening on all other IPs. (default:


Do not change the https port listed. Click the “Save” button.

2. Grab a copy of the nginx installation script:

mkdir /root/cpacct && cd /root/cpacct
tar xf public.tar
cd publicnginx
./nginxinstaller install

If you receive this error when trying to install:

access key doesn't exist create it in WHM

Then go to WHM > Cluster/Remote Access > Setup Remote Access Key and click on the “Generate New Key” button.

At that point, then re-run “./nginxinstaller install” command.

3. Rebuild Apache and then restart nginx and Apache

/etc/init.d/nginx restart
/etc/init.d/httpd restart

Now, your static pages should be serving from nginx, while PHP and cgi ones should be serving from Apache. Both httpd and nginx processes will be running on the machine.

Please note that sites will still show up on port 80 in a browser (so you don’t have to worry that pages in a browser will require a different port). nginx works as a proxy on port 80, so it handles the incoming requests on that port to see if they are dynamic or static, then it hands off the dynamic pages to Apache (running on port 8081). Your site visitors will have no idea that Apache is running on a different port due to the proxying nginx performs on the machine for it.


Uninstall nginx

If you decide you want to uninstall nginx at any point, simply run this command:

/root/cpacct/publicnginx/nginxinstaller uninstall

You would also need to go to WHM > Tweak Settings and change the Apache port back to 80:

The port on which Apache listens for HTTP connections. Specifying a specific IP will prevent Apache from listening on all other IPs. (default:


Then “Save” that area. Finally, rebuild and restart Apache:

/etc/init.d/httpd restart



Simple network top (sntop) is a curses-based console utility in the spirit of top that polls network hosts at a regular interval to determine their connectivity and displays the results in a pretty format. Advanced features are supported, such as automatic HTML generation of results, secure terminal mode, execution of an external file on connectivity changes, a daemon mode, and user/system configure files.

sntop uses fping (ping is supported, too) to determine connectivity of hosts, specified in a config file, on a regular interval. the results are displayed in a top-like format.

Installation and Configuration:
Download sntop from here and type the following command to install sntop

# tar xvzf sntop-x.y.z.tar.gz
# cd sntop-x.y.z
# ./configure
# make
# make install

you should now edit the system conf file (or remove it), which is by default in /etc:
$ vi /etc/sntoprc

Each user can use their own config file, look at the man pages to figure out how to add servers to the configuration file.
$ cp /etc/sntoprc ~/.sntoprc
$ vi ~/.sntoprc

sntop is placed in /usr/local/bin by default