Friday 11 November 2011

Math Calculator

Basic Math Calculator

#!/bin/bash
echo "**** My calculator ****"
echo "M A I N - M E N U"
echo "1. Addition"
echo "2. Multiplication"
echo "3. Subtraction"
echo "4. Remainder"
echo "5. Divide"
echo -n "Please select your choice (1-5) : "
read choice
echo -n "Enter your first number : "
read n1
echo -n "Enter your second number : "
read n2
if [ $choice -eq 1 ]
then
        answer="$n1 + $n2 = $(( $n1 + $n2 ))"
elif [ $choice -eq 2 ]
then
        answer="$n1 x $n2 = $(( $n1 * $n2 ))"
elif [ $choice -eq 3 ]
then
        answer="$n1 - $n2 = $(( $n1 - $n2 ))"
elif [ $choice -eq 4 ]
then
        answer="$n1 % $n2 = $(( $n1 % $n2 ))"
elif [ $choice -eq 5 ]
then
        answer="$n1 / $n2 = $(( $n1 / $n2 ))"
else
        echo "Sorry please select number between 1-5 only"
        exit 1
fi
echo $answer




Sunday 6 November 2011

Useful Linux Commands


1. Find and Replace text in VI editor:
:%s/wallpaper/screensaver/g
It will change all "wallpaper" word to "screensaver" in the file.

2. To delete / free page-cache, den tries and inodes:
 # echo 3 >> /proc/sys/vm/drop_caches

3. To Make a empty large file:
# dd if=/dev/zero of=bigfile bs=1G count=4
It create a 4GB of empty file. 

4. Show information of Hard Disk:
# hdparm -I /dev/sda
# iostat -dx 2

5. To check Processor 32bit or 64bit:
# getconf LONG_BIT               (It show full hardware configuration)
# lshw                                           (Recquire to install this package)

6. Which service is listening on each port:
# nmap -T4 -A -v 127.0.0.1 -p 1-65535
                -T4: For faster execution.
                -A: To enable OS and version detection
                -v: To enable verbose mode
                -p: Port range for scan only specified ports

 7. Show which program are opening/listening on those ports:
# netstat -tulp      or,
# netstat --tcp --udp --listening --program

8. Delete RAID Metadata from Hard Drives:
# cat /dev/zero /dev/sdb           (Where "sdb" is device or target name for SCSI/SATA)

9. Kill process by using port number:
# fuser 8080/tcp -k                    (It will kill 8080 port) 

10. Change wav audio format to a-law (wav) format:
# sox input.wav -A -c 1 -r 8000 output.wav

11. Mount an ISO image under Linux:
# mount -o loop disk.iso /mnt/cdrom

12. Find partition UUID (Universally Unique Identifier)
# blkid

13. Find and move larger than 30 Mb files to destination directory:
 # find ./ -size +30M -exec mv {} /Pack/ \;

14. Force delete temp files older than 30 days:
# find /tmp -mtime +30 -exec rm -f {} \;

15. Show System Hardware information: The "dmidecode" is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description  of  the  system’s  hardware  components 
DMI TYPES: The SMBIOS specification defines the following DMI types:
       Type   Information
       ----------------------------------------
          0   BIOS
          1   System
          2   Base Board
          3   Chassis
          4   Processor
          5   Memory Controller
          6   Memory Module
          7   Cache
          8   Port Connector
          9   System Slots
         10   On Board Devices
         11   OEM Strings
         12   System Configuration Options
         13   BIOS Language
         14   Group Associations
         15   System Event Log
         16   Physical Memory Array
         17   Memory Device
         18   32-bit Memory Error
         19   Memory Array Mapped Address
         20   Memory Device Mapped Address
         21   Built-in Pointing Device
         22   Portable Battery
         23   System Reset
         24   Hardware Security
         25   System Power Controls
         26   Voltage Probe
         27   Cooling Device
         28   Temperature Probe
         29   Electrical Current Probe
         30   Out-of-band Remote Access
         31   Boot Integrity Services
         32   System Boot
         33   64-bit Memory Error
         34   Management Device
         35   Management Device Component
         36   Management Device Threshold Data
         37   Memory Channel
         38   IPMI Device
         39   Power Supply
         40   Additional Information
         41   Onboard Device
# dmidecode -t 16 --type 17
# dmidecode -t 16,17
# dmidecode -t memory
# dmidecode --type MEMORY



Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...