Thursday, May 10, 2012

How to Check Swap Space in Linux ??

Linux uses Swap Space to back its physical memory with an overflow area. In most cases the suggested amount is a disk space equal to the amount of physical memory you have installed.

Below, we'll check to see how the swap is defined and being used by your system.
From your root userid, enter the command "swapon -s". This will show your allocated swap disk or disks, if any. Your output should look like the following:

Enter the command "free". This will show both your memory and your swap usage. Your output should be similar to the following:

Sunday, May 6, 2012

How to Setup two IP address on single NIC in Linux...

Setting up two IP address on one NIC

This is a small how-to to set up two are more IP address on single LAN card. There are some times which require two IP address to set up so that we can make a Linux box as a router. This can be possible without even having two NIC cards. We can configure two different IP address on single Network Card as shown below.

Setting up 2 IP address on “One” NIC. This example is on ethernet.

STEP 1:Setting up first IP address. Edit /etc/sysconfig/network-scripts/ifcfg-eth0 on Redhat Linux box and give the following entries as shown.

vi /etc/sysconfig/network-scripts/ifcfg-eth0


STEP 2: Setting up second IP address. Create one file as /etc/sysconfig/network-scripts/ifcfg-eth0:1 and give the entries as below in to this file.

vi /etc/sysconfig/network-scripts/ifcfg-eth0:1


STEP 3: Once you configure above files and save them. Now reload the network service on your machine.

#service network reload

STEP 4: Check if you get the IP address assigned to the eth0 and eth0:1 interfaces respectively.


Note1: We can assign virtual IP to the same interface with ifconfig but that one is not permanent so not giving info on that.

Note2: We can assign up to 16 virtual IP address to a single NIC card.

Friday, May 4, 2012

Convert Binary,HEX, Oct to decimal in Linux/Unix

Convert Binary,HEX, Oct to decimal

This is a small Shell tutorial on how to convert different bases to other bases.
Some times when working as system admin you require to convert different number systems to others. In this post we will see how to convert different number systems to others.

Decimal to Binary

echo "obase=2; 23" | bc


Let me explain above command. obase is a special variable in bc command which defines the output base value for a given number. There is one more special variable for bc command called ibase which defines input base value. In our example we did not mention ibase so by default it will take my input value as decimal value. So we feed obase=2 and decimal number 23 to bc command to convert decimal 23 in to binary number.

Decimal to Octal number

echo "obase=8; 23" | bc

Decimal to Hex number

echo "obase=16; 23" | bc

Decimal to any base number

convert decimal number to base 4 number system

echo "obase=4; 23" | bc

How about convert to base 7?

echo "obase=7; 23" | bc

Binary to decimal

echo "ibase=2; 11010101" | bc

Oct to decimal

echo "ibase=8; 723" | bc

Hex to decimal

echo "ibase=16; 23" | bc

How about converting binary to Oct?

echo "ibase=2;obase=8 1010101" | bc

As given above we can convert any number system to any number systems
Other ways to do base convertions

bc will convert from any base to any other base. There are some other tools which can do partially these conventions.
$(()) –can convert hex to decimal

echo $((0x123))

printf command can convert hex and oct to decimal

decimal to Octal

printf "%o\n" 123

decimal to Hex

printf "%x\n" 123

Wednesday, May 2, 2012

How to view/list only directories in Linux?

This is a small post for Linux new babies. Viewing folders can be achieved by two ways in linux/unix

Through ls command
Through find command

With ls we have to use grep to get the directory listings..

Ls –l | grep ^d


[root@test shishir_a]# ls -l | grep ^d

d——— 2 shishir_a shishir_a 4096 Sep 8 09:54 HTWFAIP

drwxrwxr-x 2 shishir_a root 4096 Nov 27 12:30 LinuxCBT – RHEL5

drwxrwxr-x 2 shishir_a root 4096 Oct 12 16:40 Software

Through find command

find . -type d

The above command will show you all the file types which are directories in present working directory.