Archive for the ‘Linux/Unix’ Category

Some useful Linux Commands

Hi friends,

Here are some Linux commands, though basic but very much useful.

1) To know the ip address of the machine
(Note – For Windows m/c its ‘ipconfig’, To get detailed information type ‘ipconfig /all’)

2) To view list of previously typed commands in command prompt
$history | grep <word that need to be searched>

3) To Know the ip address of the website
$host site-name

4) To list all the process running in a machine
$ps aux

5) To kill a process that is running
$kill -9 the process code

6) To know which process consumes more space

7) To know how much space the folder occupies
$du -sh


Read Full Post »

Linux command for Spell Check

We can spell check our documents in linux.
The following linux command is used for spell check. We need to execute this command in the console.

$spell test.txt

where test.txt is the filename for which the spell check is needed.

If the spell checker finds words that do not appear in its dictionary, it will display them on the console.
Refer this url for more info


In latest Linux distro there is one more sophisticated version of ’spell’ is available called ‘ispell’ means interactive spell checking.
Using this you can also rectify the mistakes suggested by the commands.


Read Full Post »

Friends… Many of you might have heard about the Cron Job. Specially those with some knowledge of Linux must have heard about it.
We will discuss about this CRON Funda today-

Linux O.S.

First of all, What is a Cron Job?

On Unix systems, cron is used for automating tasks. Instead of getting out of bed at 3 A.M. to run a command that can be anything from backing up a drive, or a command that deletes old files, you can use cron to schedule those tasks.

There is no actually program called “cron”. There are however, the program “crontab” and the daemon “crond”. By running the “crontab” program, you can enter commands in a text file, and they will automatically be saved in the /var/spool/cron/ directory. For example my entries (for user shruti) would be in /var/spool/cron/shruti. The crond daemon reads the files regularly and executes the commands at the time they are scheduled for.

Say for some reason, you want to check the output of the command ‘w’ every hour to see who’s on.

How to use Cron?

The setup of a crontab file is as follows:
There are six fields:

1. minute (0-59)
2. hour (0-23)
3. day of month (1-31)
4. month (1-12, or name such as jan, feb, etc)
5. day of week ( 0-6(6 = Sunday) or name such as mon, tue,etc)
6. command to run

So an example could be this:

0 1 24 5 0 w

That will run a command at 1:00AM on Monday, May 24th. Now that gets a bit cyptic. To make it a little better, this would also work:

0 1 24 may mon w

But what if you want it to run every hour, regardless of date? An “*” means that that field doesn’t matter, or do the command no matter what is in those fields. So to run our ‘w’ command every hour, the command would be this:

0 * * * * w

Which means that it runs everyday, every hour at the 0 minute mark, meaning the beginning of the hour.

A bunch of different variations of fields can be generated like this. For instance, say you wanted a command to run every 2 hours. You could specify the “hour” field as this:
*/2 Which would run at 2,4,6,8, etc…

You can also use commas to specify more than one time. For instance, say you want to run it at half past the hour, and a quarter of. You could specify the minute field as this: 30,45

If you use a dash between two values, it will include everything in between them. An example of this would be to run a command everyday for the first week of a month. The day of the month field would be this: 1-7

So to have the commmand run every 2 hours, at half past and a quarter of, and run for the first 7 days of a month. We would have this:

30,45 */2 1-7 * * w

To save the output to a text file, such as ‘wholog’ you could write the command like this:

0 * * * * w >> /home/shruti/wholog

Now by default, you will be emailed the output as well, so to avoid this, add this to the command:

0 * * * * w >> /home/shruti/wholog 2>&1

Note: root can edit other users crontabs like this: ‘crontab -e -u username’
A nice little trick is to setup a directory with a bunch of scripts you want run at a certain time, such as every hour, then make this entry in your crontab:

0 * * * * run-parts /home/shruti/hour.cron/

Or something to that effect. That command will run everything in the /home/shruti/hour.cron/ directory. /etc/crontab shows an example of this so you can check that out to see it in action.

Hope this helps you to understand a brief concept of Cron Job.
Your suggestions and comments will be gratefuly acknowledged.

Read Full Post »