Sunday, November 27, 2005

Adding Windows fonts in Linux

Unlike past times, Linux do come with good fonts. And the font rendering can be made better by choosing to antialiase the fonts. But at times you come across a website which has been designed with the windows user in mind. Such websites are best viewed with one of the windows fonts. If you have windows OS installed on your machine, you can copy the essential fonts from the windows partition to linux and use them to get a better web experience. Here is how you do it.
Method I :
Copy the ttf (True Type Fonts) fonts Ariel, Tahoma, Verdana, Courier New and Times New Roman from the windows partition to the fonts:// location in nautilus.

Method 2 :
Some people who are using Ubuntu have said that they can't do it as normal user. And since Ubuntu does not have a root account, they find difficulty in using su to copy eaither. Such people can do the following:
Create a '.fonts' folder in your home directory and copy the necessary fonts into it. Now you have access to the fonts on a per user basis.

Method 3:
This method can be used to install the fonts system wide if the above two methods do not give satisfactory results.
First find out in which location linux has installed the truetype fonts. It is usually at the location '/usr/share/fonts/truetype/' . But you may also do a search for the same as follows:
# find /usr -iname \*.ttf |head -n 5
Once you know the path of the fonts directory, move to this directory and create a folder there (it can be any name).
# cd /usr/share/fonts/truetype
# mkdir windowsfonts
Note: You need to be logged in as root while doing this.
Next copy all the windows ttf fonts to the windowsfonts directory that was just created.
# cp /media/hda1/windows/Fonts/*.ttf .
Now change the ownership of the fonts as well as make sure they have a right of 644 .
# chown root.root *.ttf
# chmod 644 *.ttf
Now run the command mkfontdir while in the windowsfonts directory.
# mkfontdir
This will create an index of the fonts in the directory. It will also create two files fonts.dir and fonts.cache-1 .
Now moving to the parent directory, edit the file fonts.cache-1 using your favourate editor and append the following line to it.
#File: /usr/share/fonts/truetype/fonts.cache-1
"windowsfonts" 0 ".dir"
Lastly run the command fc-cache.
# fc-cache
This command will scan the font directories on the system and build font information cache files for applications using fontconfig for their font handling.

That's it. Now you can have access to windows fonts in all your X applications including firefox and

Friday, November 25, 2005

Linux command line tips

Startup dir(s)

rc3.d is the normal multi user startup (non gui) bootup file in RH.
rc5.d is the normal GUI bootup file in RH.

To stop a service at bootup, you can remove the start instruction from there and that would stop the service starting.

last monitors logins
Last bad logins

lastb monitors bad logins
Make a bootable disk

Bootable disk, Mkbootdisk –device /dev/.fd0 2.0.34-1 (kernal version)


top –c To see cpu usage overall and by sevices
clear cmd line history

rm /home/joe/.bash_history (from home dir of user)
rm /.hash_history (this is for the root user)

Apache httpd.conf syntax checker (typo’s)

apachectl configtest
Samba smb.conf syntax checker (typo’s)

Command SwitchOptional FileLocation_Name

testparm /etc/samba/smb.conf
Telnet command to stop from being timed out of your session due to lack of activity (like your looking something up or going to the head).

Type “read” then press enter and when ready to start back just press enter again.

create a compress file of a directory
$tar cf - dir/* | gzip > dir.tar.gz
$tar cf - dir/* | bzip2 > dir.tar.bz2

shell loop to repeat something 20 times:
for i in `seq 1 20`; do echo "Number $i"; done

for netstat… see what programs have what ports open (probably better results when run as root):
netstat -nape --inet

kill any processes using the sound card (probably better results when run as root):
fuser -k /dev/dsp

see if a package named ‘mplayer’ is installed:
rpm -qa | grep mplayer

alias in my ~/.bashrc to get more efficient
alias r='rpm -qa | grep'

~/.bashrc alias to open the last edited file:
alias lvim='vim -c "normal '\''0"'

~/.bashrc alias to find a running process:
alias p='ps auxwww | grep'

A better ‘cd’… this does an ‘ls’ right after chaging dirs (add to ~/.bashrc):
cd() {
if [ "$PS1" ]
if [ "$1" ]
then builtin cd "$1" && ls
else builtin cd && ls
if [ "$1" ]
then builtin cd "$1"
else builtin cd

Handy disk space commands
ls -lSr #show files, biggest last
df -h #free disk space
df -i #free inodes
du -hs ... #disk usage of specified files/dirs
fdisk -l #show disks partitions sizes (run as root)

reload squid config file. it could be used with any signal and any process name. Useful when the process has more than one child.
kill -SIGHUP `pgrep squid`

shows every mounted file system whith total space, used, available and filesystem type
df -hT

useful to get directories sizes o file sizes as well
du -hs *

shows all process owned by any user in a tree (forest) way.
ps xaf


read This is an old trick to keep a telnet session from timing out on you.
fdisk -l

The minus lower case “l” displays the names of all physical and logical drives. You’ll need this if you wish to work with other drives like mounting a windows drive etc… The output on a RedHat box is like:



ls {path} It’s ok to combine attributes, eg ls -laF gets a long listing of all files with types.

ls {path_1} {path_2} List both {path_1} and {path_2}.

ls -l {path} Long listing, with date, size and permisions.

ls -a {path} Show all files, including important .dot files that don’t otherwise show.

ls -F {path} Show type of each file. “/” = directory, “*” = executable.

ls -R {path} Recursive listing, with all subdirs.

ls {path} > {filename} Redirect directory to a file.

ls {path} | more Show listing one screen at a time.

Emacs-nox text editor

Cntrl/x cntrl/s saves document
Cntrl/x cntrl/c closes document
Cntrl/k cut a individual text line
Cntrl/y paste the previously cut test line
Su - Login as root w/root profile via telnet or ssh i.e. paths for root is not the same as

VI text editor

I or esc =insert
:=preface all commands
:w= save (:w!)
:u= undo
:q= quit
:d= delete line
:p= pastes at cursor
= pastes after cursor
:yy= copies line where cursor is
:dd = deletes line at cursor
Change access permissions

chmod determines file rights, Chmod 0777 file.txt all can r/w/x, chmod 0755 file.txt public or

grp can only r/x, chmod 0644 test.txt public or grp can only read,
chmd 0711 file.txt public or grp can only x

Another to look at it is:
chmod 600 {filespec} You can read and write; the world can’t. Good for files.

chmod 700 {filespec} You can read, write, and execute; the world can’t. Good for scripts.

chmod 644 {filespec} You can read and write; the world can only read. Good for web pages.

chmod 755 {filespec} You can read, write, and execute; the world can read and execute. Good for

programs you want to share, and your public_html directory.

Grep searches a file(s) for matching pattern such as text search.

grep ‘text string’ -r /home | awk ‘{print$2}’ This goes to the monitor.

grep ‘text string’ -r /home > textstring.txt For redirect to file.

-r is recursive/home/usrname is starting point

Enable floppy disk or CD access

mount –t vfat /dev/fd0 /mnt/dos or floppy (for DOS file system) or mount /dev/fd0 (working dir is /mnt/floppy) or mount –t iso9660 /dev/cdrom /mnt/cdrom
Remove floppy disk or CD access

umount /dev/fd0 or /mnt/floppy

Wednesday, November 23, 2005

Secure remote file management with sshfs

It's a dangerous Internet out there, kids. If you are going to work on remotely connected machines, do it safely. Simple file transfers and interactive sessions have scp and ssh respectively; in fact there is hardly a commercial Web hosting provider left that doesn't support them. For more complicated scenarios we have VPN tools. But what if you need to work with files on a remote server, but find scp tedious in repetition and FreeS/WAN too cumbersome? You might find just what you're looking for in sshfs -- a tool for mounting a remote filesystem transparently and securely as if it were just another directory on your local machine.

sshfs is primarily the work of Miklos Szeredi, a Linux hacker from Budapest who is better-known as the creator of FUSE, the Filesystem in USErspace framework that makes sshfs possible. Szeredi was already working on FUSE when he discovered Florin Malita's similar project named LUFS and its SSHFS filesystem.

Szeredi liked the idea of an SSH-protected filesystem enough that he wrote a LUFS wrapper to allow him to use Malita's SSHFS in FUSE. Unhappy with the performance and lack of multi-threading, though, he eventually decided to implement his own sshfs native to FUSE.

The FUSE library and kernel module -- which joined the official Linux kernel in 2.6.14 -- enable non-root users and unprivileged programs to create and mount filesystems entirely in user space. This has led to a flurry of FUSE-based projects, providing filesystem interfaces to everything from USB-attached digital cameras to remote Gmail accounts.


But sshfs is one of the more straightforward FUSE filesystems, and thus a good place to begin for those new to FUSE. To get started, make sure that you have FUSE installed and working on your local machine. If your distribution is up-to-date, a binary package may be available to you already.

If not, you can download the source code for libfuse and the kernel module from the project's SourceForge page. Once it's installed, no further configuration is required, but you must issue a modprobe fuse command to make sure that the FUSE kernel module is loaded. You may also want to add yourself to the fuse group so you can work with FUSE without having to be root.

Next, download the sshfs source. Extract it and run ./configure and make && make install. sshfs utilizes OpenSSH's sftp package, so make sure that you have it installed on your local machine too.

You can connect to any other machine reachable via ssh; no special setup is required on the remote host. sshfs supports both SSH1 and SSH2 protocols, defaulting (as do most other tools) to SSH2. If you haven't used ssh before, you will need to generate a key pair and perform some basic ssh configuration. See the tutorials at for more help.


The general form for mounting an sshfs filesystem is sshfs username@remote_hostname:directory local_mount_point -- where username is the username of your account on the remote host. If it is the same as your local username, you may safely omit it and the @ sign.

If you do not specify a directory on the remote host, the user account's home directory is assumed -- but you must not omit the trailing colon in this case (e.g., sshfs ~/webstuff).

Once the remote directory is mounted, it behaves like any other local filesystem, visible to all scripts and applications, but over an end-to-end encrypted channel. You can browse and drag-and-drop files with Nautilus or Konqueror, edit files as if they were local, even work with a CVS repository.

When you are done working, the command fusermount -u local_mount_point unmounts the filesystem and tears down the connection.

If you intend to make regular use of an sshfs filesystem, you can add it to /etc/fstab and have it mounted automatically. Before doing this, however, make sure that the FUSE kernel module is loaded at startup time by adding it to /etc/modules.


Read and write performance is fast with sshfs. To get a feel for the system, I connected to an off-site backup server over my cable modem and tried to work my usual routine to compare real-world performance. I found no discernible time difference between commands acting on the remote system and local files. By contrast, NFS mounts frequently incur a noticeable lag, and WebDAV is slower than molasses.

Of course, two of the advantages to WebDAV are the collaborative editing of documents and revision tracking, which sshfs is not designed for. On the other hand, sshfs is far superior to scp because the entire command-line toolset operates on it.

For moving files from one machine to another, scp does a fine job -- but when it comes to searching, batch operations, cron jobs, or editing in place, sshfs wins hands down. As Szeredi told me, the convenience of filename auto-completion alone makes the whole system worthwhile.

sshfs reached version 1.0 last January. The current 1.3 release is essentially feature-complete, though Szeredi says there is still some work to be done. Certain command-line tools (such as df) do not work properly due to shortcomings in the OpenSSH implementation of sftp. To work around these holes, sshfs has to estimate disk usage and free space, which could complicate its usage for some tasks.

But even when it is completed, Szeredi points out that sshfs will not replace high-end systems like NFS or VPNs. It is intended only to provide fast, convenient access to remote directories, and do so securely, and with no configuration required on the remote host.

Tuesday, November 22, 2005

Regular Expression in Vi, Sed, grep, egrep

Here are a few representative, simple examples.

vi command

What it does

:%s/ */ /g

Change 1 or more spaces into a single space.

:%s/ *$//

Remove all spaces from the end of the line.

:%s/^/ /

Insert a space at the beginning of every line.

:%s/^[0-9][0-9]* //

Remove all numbers at the beginning of a line.


Change all occurences of bag, beg, big, and bog, to bug.


Change all occurences of tag, tog, and tug to hat, hot, and hug respectively.

Medium Examples (Strange Incantations)

Example 1

Change all instances of foo(a,b,c) to foo(b,a,c). where a, b, and c can be any parameters supplied to foo(). That is, we must be able to make changes like the following:







foo( bar(8), x+y+z, 5)

foo( x+y+z, bar(8), 5)

The following substitution command will do the trick :


Now, let's break this apart and analyze what's happening. The idea behind this expression is to identify invocations of foo() with three parameters between the parentheses. The first parameter is identified by the regular expression \([^,]*\), which we can analyze from the inside out.


means any character which is not a comma


means 0 or more characters which are not commas


tags the non-comma characters as \1 for use in the replacement part of the command


means that we must match 0 or more non-comma characters which are followed by a comma. The non-comma characters are tagged.

This is a good time to point out one of the most common problems people have with regular expressions. Why would we use an expression like [^,]*, instead of something more straightforward like .*, to match the first parameter? Consider applying the pattern .*, to the string "10,7,2". Should it match "10," or "10,7," ? To resolve this ambiguity, regular expressions will always match the longest string possible. In this case "10,7," which covers two parameters instead of one parameter like we want. So, by using the expression [^,]*, we force the pattern to match all characters up to the first comma.

The expression up to this point is: foo(\([^,]*\), and can be roughly translated as "after you find foo( tag all characters up to the next comma as \1". We tag the second parameter just like the first and it can be referenced as \2. The tag used on the third parameter is exactly like the others except that we search for all characters up to the right parenthesis. It may be superfluous to search for the last parameter since we don't have to move it. But this pattern guarantees that we update only those instances of foo() where 3 parameters are specified. In these times of function and method overloading, being explicit often proves to be useful. In the substitution portion of the command, we explicitly enter the invocation of foo() as we want it, referencing the matched patterns in the new order where the first and second parameter have been switched.

Example 2

We have a CSV (comma separated value) file with information we need, but in the wrong format. The columns of data are currently arranged in the following order: Name, Company Name, State, Postal Code. We need to reorganize the data into the following order in order to use it with a particular piece of software: Name, State-Postal Code, Company Name. This means that we must change the order of the columns in addition to merging two columns to form a new column value. The particular piece of software that needs this data will not work if there are any whitespace characters (spaces or tabs) before or after the commas. So we must remove whitespace around the commas.

Here are a few lines from the data we have:

    Bill Jones, HI-TEK Corporation , CA, 95011
    Sharon Lee Smith, Design Works Incorporated, CA, 95012
    B. Amos , Hill Street Cafe, CA, 95013
    Alexander Weatherworth, The Crafts Store, CA, 95014

We need to transform them to look like this:

    Bill Jones,CA 95011,HI-TEK Corporation
    Sharon Lee Smith,CA 95012,Design Works Incorporated
    B. Amos,CA 95013,Hill Street Cafe
    Alexander Weatherworth,CA 95014,The Crafts Store

We'll look at two regular expressions to solve this problem. The first moves the columns around and merges the data. The second removes the excess spaces.

Here is the first pass at a substitution command that will solve the problem:

    :%s/\([^,]*\),\([^,]*\),\([^,]*\),\(.*\)/\1,\3 \4,\2/

The approach is similar to that of Example 1. The Name is matched by the expression \([^,]*\), that is, all characters up to the first comma. The name can then be referenced as \1 in the replacement pattern. The Company Name and State fields are matched just like the Name field and are referenced as \2 and \3 in the replacement pattern. The last field is matched with the expression \(.*\) which can be translated as "match all characters through the end of the line". The replacement pattern is constructed by calling out each tagged expression in the appropriate order and adding or not adding the delimeter.

The following substitution command will remove the excess spaces:

    :%s/[ \t]*,[ \t]*/,/g

To break it down: [ \t] matches a space or tab character; [ \t]* matches 0 or more spaces or tabs; [ \t]*, matches 0 or more spaces or tabs followed by a comma; and finally [ \t]*,[ \t]* matches 0 or more spaces or tabs followed by a comma followed by 0 or more spaces or tabs. In the replacement pattern, we simply replace whatever we matched with a single comma. The optional g parameter is added to the end of the substitution command to apply the substitution to all commas in the line.

Example 3

Suppose you have a multi-character sequence that repeats. For example, consider the following:

Billy tried really hard
Sally tried really really hard
Timmy tried really really really hard
Johnny tried really really really really hard

Now suppose you want to change "really", "really really", and any number of consecutive "really" strings to a single word: "very". The command

:%s/\(really \)\(really \)*/very /

changes the text above to:

Billy tried very hard
Sally tried very hard
Timmy tried very hard
Johnny tried very hard

The expression \(really \)* matches 0 or more sequences of "really ". The sequence \(really \)\(really \)* matches one or more instances of the sequence "really ".

Hard Examples (Magical Hieroglyphics)

coming soon.

OK, you'd like to use regular expressions, but you can't bring yourself to use vi. Here, then, are a few examples of how to use regular expressions in other tools. Also, I have attempted to summarize the differences in regular expressions you will find between different programs.

You can use regular expressions in the Visual C++ editor. Select Edit->Replace, then be sure to check the checkbox labled "Regular expression". For vi expressions of the form :%s/pat1/pat2/g set the Find What field to pat1 and the Replace with field to pat2. To simulate the range (% in this case) and the g option you will have to use the Replace All button or appropriate combinations of Find Next and Replace


Sed is a Stream EDitor which can be used to make changes to files or pipes. For complete details, see the man page sed

Here are a few interesting sed scripts. Assume that we're processing a file called price.txt. Note that the edits don't actually happen to the input file, sed simply processes each line of the file with the command you supply and echos the result to its standard out.

sed script


sed 's/^$/d' price.txt

removes all empty lines

sed 's/^[ \t]*$/d' price.txt

removes all lines containing only whitespace

sed 's/"//g' price.txt

remove all quotation marks


Awk is a programming language which can be used to perform sophisticated analysis and manipulation of text data. For complete details, see the man page awk Its peculiar name is an acronym made up of the first character of its authors last names (Aho, Weinberger, and Kernighan).

There are many good awk examples in the book The AWK Programming Language (written by Aho, Weinberger, and Kernighan). Please don't form any broad opinions about awk's capabilities based on the following trivial sample scripts. For purposes of these examples, assume that we're working with a file called price.txt. As with sed, awk simply echos its output to its standard out.

awk script


awk '$0 !~ /^$/' price.txt

removes all empty lines

awk 'NF > 0' price.txt

a better way to remove all lines in awk

awk '$2 ~ /^[JT]/ {print $3}' price.txt

print the third field of all lines whose second field begins with 'J' or 'T'

awk '$2 !~ /[Mm]isc/ {print $3 + $4}' price.txt

for all lines whose second field does not contain 'Misc' or 'misc' print the sum of columns 3 and 4 (assumed to be numbers).

awk '$3 !~ /^[0-9]+\.[0-9]*$/ {print $0}' price.txt

print all lines where field 3 is not a number. The number must be of the form: d.d or d. where d is any number of digits from 0 to 9.

awk '$2 ~ /John|Fred/ {print $0}' price.txt

print the entire line if the second field contains 'John' or 'Fred'


grep is a program used to match regular expressions in one or more specified files or in an input stream. Its name programming language which can be used to perform data manipulation on files or pipes. For complete details, see the man page grep. Its peculiar name stems from its roots as a command in vi, g/re/p meaning global regular expression print.

For the examples below, assume we have the text below in a file named phone.txt. Its format is last name followed by a comma, first name followed by a tab, then a phone number.

    Francis, John 5-3871
    Wong, Fred 4-4123
    Jones, Thomas 1-4122
    Salazar, Richard 5-2522

grep command


grep '\t5-...1' phone.txt

print all the lines in phone.txt where the phone number begins with 5 and ends with 1. Note that the tab character is represented by \t.

grep '^S[^ ]* R' phone.txt

print lines where the last name begins with S and first name begins with R.

grep '^[JW]' phone.txt

print lines where the last name begins with J or W

grep ', ....\t' phone.txt

print lines where the first name is 4 characters. The tab character is represented by \t.

grep -v '^[JW]' phone.txt

print lines that do not begin with J or W

grep '^[M-Z]' phone.txt

print lines where the last name begins with any letter from M to Z.

grep '^[M-Z].*[12]' phone.txt

print lines where the last name begins with a letter from M to Z and where the phone number ends with a 1 or 2.


egrep is an extended version of grep. It supports a few more metacharacters in its regular expressions. For the examples below, assume we have the text below in a file named phone.txt. Its format is last name followed by a comma, first name followed by a tab, then a phone number.

    Francis, John 5-3871
    Wong, Fred 4-4123
    Jones, Thomas 1-4122
    Salazar, Richard 5-2522

egrep command


egrep '(John|Fred)' phone.txt

print all lines that contain the name John or Fred.

egrep 'John|22$|^W' phone.txt

print lines that contain John or that end with 22 or that begin with W.

egrep 'net(work)?s' report.txt

print lines in report.txt contain networks or nets.

Command or


[ ]



\( \)

\{ \}




( )







Visual C++








































































The vi Substitution Command

Vi's substitution command has the form



    : begins an ex (command line editor) command which is applied to the file currently being edited.

    range is the line range specifier. Use the percent sign (%) to indicate all lines. Use the dot (.) to indicate the current line. Use the dollar sign to indicate the last line. You can also use specific line numbers. Examples: 10,20 means lines 10 through 20; .,$ means from the current line to the last line; .+2,$-5 means from two lines after the current through the fifth line up from the end of the file.

    s is the substitution command.

    pat1 is the regular expression to be searched for. This paper is full of examples.

    pat2 is the replacement pattern. This paper is full of examples.

    g is optional. When present the substitution is made to all matches on the line. When it is not present, the substitution is applied only to the first match on the line.

Monday, November 21, 2005

ClamAV - The free Anti Virus solution for Windows on Linux

There is a common perception that there are no viruses on the Linux platform - which to a large extent is true. But what happens when you get a mail attachment which you would like to forward to your windows machine so you can open it with your favorite proprietary software? And what if this attachment is infected by a virus? This is where the anti virus solutions for linux comes into the picture.
ClamAV is a free GPLed anti-virus solution which provides a lot of advantages when installed in Linux. Sticking to the philosophy of linux, it contains a set of command line tools which can be used to check if a file on your system is infected by a virus.
The installation is quite simple as executing a single command as follows:

# yum install clamav
(for RedHat based systems)
# apt-get install clamav
(for Debian based systems)

ClamAV basically installs three binary tools on your system (in the /usr/bin directory), them being :
freshclam - As you know an anti-virus solution is only as good as the latest virus updates it has. This tool is used to update the virus databases on your system. It downloads the latest virus updates from the internet and keeps your anti-virus solution upto date.
clamscan - This is the tool that actually checks your files to see if they are infected.
sigtool - When you download the latest virus updates from the net, there should be a way of verifying the validity of the update. This is achieved by the sigtool. It is used to verify the digital signatures of databases and list virus signature names among other things.

This is how I use this wonderful package to my advantage. I have installed Linux alongside windows and boot via Grub bootloader (most people do). I have a FAT and NTFS partition on my harddrive which I have mounted in /mnt/C:/ and /mnt/D:/ . To check all the files in my windows partition, I just enter the command as follows (you don't have to be root to run this command):
$ clamscan --bell -r --log=/home/ravi/virus_log -i /mnt/D:/

The above command will scan my /mnt/D:/ directory (FAT32 partition) recursively (-r) and log (--log) the result in the virus_log file, will beep (--bell) each time a virus has been detected and only print (-i) infected files to the output.

clamscan can scan a wide variety of files including archive files (rar, zip, tar, deb, jar, arj ), your mails, html files ... In fact just about any file on your system.

For instance, if I want to scan a tar file, I will enter the following command:

$ clamscan --tar=/bin/tar  myfile.tgz
Same is the case for other archives. You pass the path of the archive tool in the command line.

Usually clamscan will recurse through a maximum depth of 15 levels if the -r option is used. But you can set the depth of recursion using the --max-dir-recursion option.
$ clamscan -r --max-dir-recursion=4 ~ravi/.

Here is another example of how you check only the text files on your harddisk for virus infection.
$ find . -iname \*.txt -exec clamscan -r -i {} \;

Updating the virus database
You will agree with me that the usefulness of an anti-virus solution is only as good as its virus definition files. With ClamAV, it is very easy to update the database. All it takes is executing the command :
# freshclam

And ClamAV will download the latest virus definition files from the internet and update your database. You can also run the above command as a daemon as follows:
# freshclam -d
Usually you don't have to run this command yourselves. When you install ClamAV on your machine, it creates a user and group named 'clamav' and also creates a cron job to update on a regular basis, the virus database on your machine.

ClamAV has been developed targeting firms running mail servers in mind and so is designed to check for virus on the fly. If you manage a mail server, you can integrate it with sendmail or any other mail server to check your incoming and outgoing emails for viruses.

Advantages of Clamav over other Anti-Virus suites
  1. The one and only GPLed Anti-Virus solution available with an unbeatable price tag (Free).
  2. Multi architecture and multi OS support. Clamav is available for MacOS, Windows, Linux and other Unix variants.
  3. Simple command line usage - which does away with memory bloat that other anti-virus solutions carry around. I still remember the times when my windows 98 machine would slow to a crawl when an antivirus package was installed on it.
  4. Can be linked with other linux commands to create powerful filters to check just a subset of files on your machine.
  5. You can automate the whole process of virus detection and prevention.
  6. Easy installation and uninstallation - I remember the trouble I had in uninstalling Norton Antivirus from my windows 98 machine a few years back. When I tried to uninstall Norton Antivirus, it said I should uninstall "Live Update" first and when I tried uninstalling the latter, it complained that "Norton Antivirus" was running and should be uninstalled first - in short a catch 22 situation - the only way out being a clean re-installation of windows OS. Clamav doesn't have any such problems.
  7. Lots of third party softwares with in-built support for ClamAV. For example, DansGuardian virus patch is a GPL addon that takes the virus scanning capabilities of ClamAV and integrates them into the content filtering web proxy DansGuardian.
What? You don't want to install the Clam Antivirus package just yet ? No problem, there is a Online scanning tool available from ClamAV which will help you scan a file on your harddisk without installing it.

MySQL - Cheat Sheet

MySQL is a small, fast and highly configurable DBMS. It supports a number of different table fileformats, depending on the requirements of the user.
These are the main MySQL clients and processes (mysqld):
mysqld - MySQL server daemon
safe_mysqld - Server process monitor
mysqlaccess - Tool for creating MySQL users
mysqladmin - Utility for administering MySQL
mysqldump - Tool for dumping the contents of a MySQL database
mysql - Command line interface to MySQL
mysqlshow - List all MySQL database

Field Types in SQL
INTEGER - A whole number
VARCHAR(10) - Up to 10 characters.
CHAR(10) - Fixed number of characters
DATE - A date
DATETIME - Date and time
FLOAT - Floating point numbers
Field Types specific to MySQL
TEXT - Allows up to 65535 characters
DECIMAL(10,2) - Up to 10 digits before the point, 2 after.
Create a database
$ mysqladmin --user=ravi --password=xxx create database addressdb
Using the database
$ mysql --user=ravi --password=xxx
mysql> USE addressdb
Create a table
mysql> CREATE TABLE p_addr (i INTEGER PRIMARY KEY,address TEXT,email VARCHAR(30),pincode DECIMAL(10),phone DECIMAL(15),website TEXT);
Add a column called "name" to the table
mysql> ALTER TABLE p_addr ADD name VARCHAR(30);
Inserting values into table
mysql> INSERT INTO p_addr VALUES (1,"My, present, address","ravi@localhost",681024,2122536, "","Ravi");
List the contents of the table
mysql> SELECT * FROM p_addr;
Delete a row from the table
mysql> DELETE FROM p_addr WHERE i=1;
Rename a column in the table from "address" to "home_address"
mysql> ALTER TABLE p_addr CHANGE address home_address INTEGER;
Note: You cannot use this method to rename a column which is a primary key.

Change an existing record in the table
mysql> UPDATE p_addr SET name="Sumitra" WHERE i=2;
Delete the table from the database
mysql> DROP TABLE p_addr;
List the databases
$ mysqlshow --user=ravi --password=xxx
| Databases |
| addressdb |
| myblog |
| mysql |
| test |
List the tables in the database "addressdb"
$ mysqlshow --user=ravi --password=xxx addressdb
Database: addressdb
| Tables |
| p_addr |
| mytble |
| phonebk |
These are only a subset of the commands in mysql. But this will be enough for creating and maintaining a simple database.

Sunday, November 20, 2005

Upper Case to Lower Case

Unix way' of doing things.

Let's take a small sample file, `dat' containing the words:


Some words begin with an uppercase character, the step to convert everything to lowercase:

cat dat | tr 'A-Z' 'a-z'

Now, do a dictionary sort based on the first word:
cat dat | tr 'A-Z' 'a-z' | sort

Isn't it interesting?

Saturday, November 19, 2005

Backup and Restore Mysql Database

Backup your database

mysqldump -uusername -ppassword databasename > backupfile.sql

Add drop table - This option is useful if you would like to create a backup file which can rewrite an existing database without having to delete the older database manually first.

mysqldump –add-drop-table -uusername -ppassword databasename > backupfile.sql

Directly compress data from a database

mysqldump -uusername -ppassword databasename | gzip > backupfile.sql.gz

Back up only specified tables

mysqldump -uusername -ppassword databasename specific_table1 specific_table2 >

Backup multiple databases

mysqldump -uusername -ppassword –databases databasename1 databasename2
databasename3 > multibackupfile.sql

Back up only the database structure

mysqldump –no-data –databases databasename1 databasename2 databasename3 >

Backup up all databases on a server

mysqldump –all-databases > allbackupfile.sql

Restore database

mysql -uusername -ppassword databasename <>

Restoring zipped files

gunzip <>

Moving database to a new server

mysqldump -uusername -ppassword databasename | mysql –host= -C

Without Shell Access

Use phpMyAdmin

Backup a database

Select the database in the left navigation frame, which should bring up the
database details in the main frame

Select the Export tab

Under Export, select SQL

Select Structure if you’ll be using the data to create new tables

Select Add drop table if the data is intended to completely replace tables

Select Data

Select Save as File

Select your preferred compression format (none, zipped, gzipped, or bzipped)

Click Go (bottom-right)

The mysql data should download to your browser’s default download destination.

Restore a database

Select the SQL tab in the main phpMyAdmin frame

Click Choose File

Locate the SQL file on your computer

Once you’ve selected your import file, click Go

If you get any Table already exists errors while importing data, resave the sql with the Add drop table option checked, or simply delete the conflicting tables and run the import again.

If you encounter any problem, drop a comment and I will try to solve.