Search This Blog

Tuesday, September 10, 2013

Use of stat command....

Use stat command. It displays file or file system status such as:

=> File size

=> File type

=> Inode number

=> UID/GID

=> File access , modify and creation time etc.
stat command example

$ stat /etc/passwd

Display file system status

You can display file system status instead of file status. For example, display status for / file system:

$ stat -f /

Set timezone using /etc/localtime configuration file [any Linux distro]

Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.


Create a symlink to file localtime:

# ln -sf /usr/share/zoneinfo/EST /etc/localtime

Eg: # ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime

date -s "10/15/2005 09:40:00 EDT"

date -s "10/15/2005 09:40:00"
/sbin/hwclock --systohc


Edit the /etc/sysconfig/clock text file so that it looks like this:

ZONE="America/Denver"
UTC=true
ARC=false

Of course, this assumes that your hardware clock is running UTC time...

3. Delete the following file: /etc/localtime

4. Create a new soft link for /etc/localtime. Here is an example of step 3 and step 4:

# cd /etc
# ls -al localtime
lrwxrwxrwx 1 root root 39 Mar 28 07:00 localtime -> /usr/share/zoneinfo/America/Los_Angeles

# rm /etc/localtime

# ln -s /usr/share/zoneinfo/America/Denver /etc/localtime
# ls -al localtime
lrwxrwxrwx 1 root root 34 Mar 28 08:59 localtime -> /usr/share/zoneinfo/America/Denver

# date
Fri Mar 28 09:00:04 MST 2003


date; date > ~/date."bak-`/bin/date`"; cat /etc/sysconfig/clock; ls -l /etc/localtime

NTP Configuration and Usage:

Various Port Numbers for Quick Ref.

 Hi Guys
 
A quick ref for various port numbers.
 
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
21 => FTP
22 => SSH
23 => Telnet
25 => SMTP Mail Transfer
43 => WHOIS service
53 => name server (DNS)
80 => HTTP (Web server)
110 => POP protocol (for email)
443 => HTTP Secure (SSL for https:// ) 
995 => POP over SSL/TLS
9999 => Urchin
3306 = > MysQL Server
2082 => CPANEL Default
2083 => CPANEL - Secure/SSL
2086 => CPANEL WHM
2087 => CPANEL WHM - Secure/SSL
2095 => cpanel webmail
2096 => cpanel webmail - secure/SSL
Plesk Control Panel => 8880
Plesk Control Panel => 8443
DirectAdmin Control Panel => 2222
Webmin Control Panel => 10000
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

A simple script that will help you to understand the usage of [if elif else fi] and check whether file or directory.

vi delete.sh

#code goes here.


#------------------------------------------------------------------------------------------

#!/bin/bash

echo -n "Enter the filename : ";
read myfile;
echo -n "Are you sure (Yes/No)?"
read confirm;

#Checking the entered file type

if [ -f $myfile ]; then
value="File"
elif [ -d $myfile ]; then
value="Directory"
else
value="Special file"
fi

#user confirmation for deletion

confirm="$(echo ${confirm} | tr 'A-Z' 'a-z')"
if [ "$confirm" == "yes" ]; then

#deleting the file/directory

[ -f $myfile ] || [ -d $myfile ] &&  /bin/rm -r $myfile && echo "$value $myfile has been deleted"|| echo "Error - Unable to locate the file $myfile"

else
echo " Program exiting...."
fi
#------------------------------------------------------------------------------------------

Monday, September 09, 2013

View the Content of initrd image in Linux

The initial RAM disk is an initial root file system that is mounted prior to when the real root file system is available.

How can the content of initrd can be viewed?

Go to the /boot directory of linux and copy the initrd file to another location.

1. Create a folder

[ajasoman@oc1120611582 ~]$ mkdir initrd

2. Change to that directory and copy the initrd file to there..

[ajasoman@oc1120611582 ~]$ cd initrd

[ajasoman@oc1120611582 initrd]$ cp /boot/initramfs-2.6.32-358.11.1.el6.x86_64.img /home/ajasoman/initrd

[ajasoman@oc1120611582 initrd]$ ls initramfs-2.6.32-358.11.1.el6.x86_64.img

3. Rename the file to .gz

mv initramfs-2.6.32-358.11.1.el6.x86_64.img initramfs-2.6.32-358.11.1.el6.x86_64.gz

4. Use gunzip command to un-compress the file

gunzip initramfs-2.6.32-358.11.1.el6.x86_64.gz

5. Use cpio command to convert

[ajasoman@oc1120611582 initrd]$ cpio -ivd < initramfs-2.6.32-358.11.1.el6.x86_64
.
initqueue-finished
proc
pre-udev
pre-udev/30block-genrules.sh
pre-udev/30dmsquash-liveiso-genrules.sh
pre-udev/30dm-pre-udev.sh
pre-udev/30resume-genrules.sh
pre-udev/30mdmon-pre-udev.sh
dracut-004-303.el6
lib64
lib64/li
6. See the o/p using ls 

[ajasoman@oc1120611582 initrd]$ ls -l
total 50300
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 bin
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 cmdline
drwxr-xr-x 3 ajasoman ajasoman     4096 Sep  9 23:40 dev
-rw-r--r-- 1 ajasoman ajasoman       19 Sep  9 23:40 dracut-004-303.el6
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 emergency
drwxr-xr-x 7 ajasoman ajasoman     4096 Sep  9 23:40 etc
-rwxr-xr-x 1 ajasoman ajasoman     8879 Sep  9 23:40 init
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 initqueue
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 initqueue-finished
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 initqueue-settled
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 initqueue-timeout
-rw-r--r-- 1 ajasoman ajasoman 51398656 Sep  9 23:11 initramfs-2.6.32-358.11.1.el6.x86_64
drwxr-xr-x 7 ajasoman ajasoman     4096 Sep  9 23:40 lib
drwxr-xr-x 4 ajasoman ajasoman     4096 Sep  9 23:40 lib64
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 mount
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 pre-pivot
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 pre-trigger
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 pre-udev
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 proc
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 sbin
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 sys
drwxr-xr-x 2 ajasoman ajasoman     4096 Sep  9 23:40 sysroot
drwxrwxrwt 2 ajasoman ajasoman     4096 Sep  9 23:40 tmp
drwxr-xr-x 7 ajasoman ajasoman     4096 Sep  9 23:40 usr
drwxr-xr-x 4 ajasoman ajasoman     4096 Sep  9 23:40 var
[ajasoman@oc1120611582 initrd]$