Archive for the ‘ Linux ’ Category

Handy commands

-List files opened by a program listening on a certain port (lsof -i:port)

lsof -i:3306

-Benchmark the performance of a webserver

ab -n 100 -c 5 http://www.sample-mysite.com/test.php

Send 100 request with 5 concurrent connections.

-Search for a string/pattern in all subdirectories of the given path

 find /my/path -exec grep 'hairy' {} /dev/null \;

Tips on changing file permissions in bulk.

First command – changes all directories under the current directory to 700 file mode.

find . -type d -exec chmod 0700 {} \;

Second command – changes all files under the current directory to 600 mode.

find . -type f -exec chmod 0600 {} \;

time stamp on history

The ‘history’ commands does not display the exact date and time of the commands executed. It just shows a numeric id followed by  the command executed by the current user. Here is one way of putting a time stamp –

 export HISTTIMEFORMAT='%F %T  ' 

To make sure that it works every time you login or restart your machine, put it in $HOME/.bash_profile

Other useful environment variable related to the history command are –

1. HISTFILE
The name of the file in which command history is saved.

2. HISTFILESIZE
The maximum number of lines contained in the history file.

3. HISTIGNORE
A colon-separated list of patterns used to decide which command lines should be saved on the history list.

4. HISTSIZE
The number of commands to remember in the command history.

Setting clock

Some times you might be able to execute very complex commands and write pages of shell scripts and yet find your-self in a clueless situation, like the seemingly mundane task of setting the data/time in your Linux box from the command line. Here are a couple of ways that might help –

1. Using /etc/localtime and /usr/share/zoneinfo

Create a link to the file in /usr/share/zoneinfo which contains the time zone you want to set your clock to.

ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

2. Edit /etc/sysconfig/clock

vi /etc/sysconfig/clock

-set the “ZONE” variable to your region – like “US/Central”

3.  Export command

Export TZ=America/New_York

4. Set the date using date command –

Example

date -s '2010-07-09 13:19:55'

5. Hardware clock

hwclock --set --date='07/09/2010 13:19:55'

One of the things which makes Linux more appealing is the capability to send email from command line, without logging to a webmail account or configuring your mail client like Outlook express. While working on the command line, you can send an attachment too, but the problem with this is file attachments like pdf or jpg appear as garbled text to the receiver. The solution? Another cool opensource software: uuencode. Download uuencode from this site for ubuntu: http://packages.ubuntu.com/dapper/i386/sharutils/download.

Usage: Suppose you want to send a pdf file(‘climatechange.pdf’) to a recipient address mrxyz@hisdomain.com. Then type the following command:

$uuencode climatechange.pdf climatechange.pdf | mails -s "climate change document" mrxyz@hisdomain.com

The pdf document wil appear as an attachment on the recipients side. Read More

Superfast distro out there

If you are looking for a lightweight, lean&mean operating system oriented towards web applications, then download and play with Peppermint Linux. It has just been released in the last few days.
http://peppermintos.com/