Showing posts with label Unix Commands. Show all posts
Showing posts with label Unix Commands. Show all posts

Monday, February 10, 2014



In previous article, we understood the column wise information about netstat output. In this article, we will understand the different examples and uses of this command.

How to get interface statistics?

When we use –i flag with netstat command, it gives the currently configured interface statistics. If we use –a option then it gives all interface’s statistics.
[root@server1 Downloads]# netstat –I
Kernel Interface table
Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500   0    39784      0      0      0      568      0      0      0 BMRU
lo        16436   0       16      0      0      0       16      0      0      0 LRU
[root@server1 Downloads]#
[root@server1 Downloads]# netstat -ia
Kernel Interface table
Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500   0    40698      0      0      0      639      0      0      0 BMRU
lo        16436   0       16      0      0      0       16      0      0      0 LRU
pan0       1500   0        0      0      0      0        0      0      0      0 BM
sit0       1480   0        0      0      0      0        0      0      0      0 O
[root@server1 Downloads]#

Columns showing information about the packet status as follow:

MTU
Maximum transmission unit
Met
Metric values for that interface
RX-OK/TX-OK
How many packets received or transmitted successfully
RX-ERR/TX-ERR
Errors in packets(not delivered successfully)
RX-DRP/TX-DRP
Number of packets dropped
RX-OVR/TX-OVR
Number of packets are lost because of overrun
Flags
Flags that have been set for interface.

There are different types of flags. We got four types of flag in above example. Below is the short information about these flags.

B
Broadcast address has been set for this interface
O
Address resolution protocol is turned off for this interface
U
Interface is up
P
Point to point connection
R
Interface is running
L
Interface is a loopback device
M
All packets received successfully

How to display different types of connections using netstat command?
TCP, UDP and RAW and unix socket connection we can see by using –t, -u, -w, and –x flags with netstat command. Detailed description about this you will get in this article.
Posted by Machindra Dharmadhikari On 2/10/2014 10:19:00 PM No comments READ FULL POST

Friday, October 25, 2013


Sticky bit is a bit set in permission of a file or directory to give special access –rights to user. When we set the sticky bit for any executable file, it will remain in swap space after the process exited. It will help to reduce time of execution in repeatedly used programs. So, we can set this sticky bit for frequently used programs like editors, commands etc. So, execution of them will be faster as compared to without sticky bit.
Main important use of sticky bit is on directory, when we set sticky bit for directory then files reside in the directory can delete or rename by owner only. This is helpful not to give access for renaming or deletion to unauthorized user. When sticky bit is not set for directory then any user having permission to write and execute on directory can rename and delete files inside the directory.

Sticky bit behavior or feature changes as per operating system. Linux Kernel ignores the sticky bit on files, it considers only on directories. In HP-UX work on sticky bit as above mentioned. In AIX, if we set the sticky bit for directory then only owner can link or unlink the directory or files specified in the directory.

How to set Sticky bit on file/directory in Linux?

We will set sticky bit by chmod command. For this purpose, we can use octal mode or by its symbol ‘t’. lets go through the example.

//Check the permissions of directory sticky
redhat@localhost:~/mywork$ ls -l
total 4
drwxr-xr-x 2 redhat adm 4096 2013-10-24 15:36 sticky
redhat@localhost:~/mywork$ ls -l sticky/                            //inside directory permissions
total 8
-rwxr-xr-x 1 redhat adm 57 2013-10-24 15:35 stickybit.sh
-rwxr-xr-x 1 redhat adm 57 2013-10-24 15:36 stickybit.sh_bak
//Adding sticky bit in permission by below syntax ..or use - chmod 1755 sticky
redhat@localhost:~/mywork$ chmod +t sticky/                         
redhat@localhost:~/mywork$ ls -l sticky/
total 8
-rwxr-xr-x 1 redhat adm 57 2013-10-24 15:35 stickybit.sh
-rwxr-xr-x 1 redhat adm 57 2013-10-24 15:36 stickybit.sh_bak
redhat@localhost:~/mywork$ ls -l
total 4
drwxr-xr-t 2 redhat adm 4096 2013-10-24 15:36 sticky
//In above line sticky bit added in permissions
redhat@localhost:~/mywork$


Now we have set the sticky bit to directory. Now we will try to remove file or script inside the directory.

//Changing the user. Sandeep and redhat having same group.
redhat@localhost:~/mywork/sticky$ su - Sandeep
Password:
Sandeep@localhost:~$
Sandeep@localhost:~$ pwd
/home/Sandeep
Sandeep@localhost:~$ cd ../redhat            //Change Directory to that sticky bit directory
Sandeep@localhost:/home/redhat$ ls
mywork
Sandeep@localhost:/home/redhat$ ls -l
total 4
drwxr-xr-x 3 redhat adm 4096 2013-10-24 15:39 mywork
Sandeep@localhost:/home/redhat$ cd mywork/
Sandeep@localhost:/home/redhat/mywork$ ls -l
total 4
drwxr-xr-t 2 redhat adm 4096 2013-10-24 15:36 sticky
Sandeep@localhost:/home/redhat/mywork$
Sandeep@localhost:/home/redhat/mywork$ cd sticky/
Sandeep@localhost:/home/redhat/mywork/sticky$ ls
stickybit.sh  stickybit.sh_bak
//Trying to remove sticky bit set directory content ..getting error permission denied
Sandeep@localhost:/home/redhat/mywork/sticky$ rm stickybit.sh
rm: remove write-protected regular file `stickybit.sh'? y
rm: cannot remove `stickybit.sh': Permission denied
Sandeep@localhost:/home/redhat/mywork/sticky$

Permission denied while removing the file which resides into the directory whose sticky bit has been set already. This is the actual use of sticky bit on directory.

How to remove sticky bit of directory/file ?

We need to login by redhat or root user before removing sticky bit then only we can remove the Sticky bit.

redhat@localhost:~/mywork$ ls –l
total 4
drwxr-xr-t 2 redhat adm 4096 2013-10-24 15:36 sticky
//use below syntax or use – chmod 755 sticky
redhat@localhost:~/mywork$ chmod -t sticky/
redhat@localhost:~/mywork$ ls -l
total 4
drwxr-xr-x 2 redhat adm 4096 2013-10-24 15:36 sticky
redhat@localhost:~/mywork$


Drop an email if you have any query regarding the Linux issue or like our page on Facebook and post a query.
Posted by Machindra Dharmadhikari On 10/25/2013 09:29:00 PM No comments READ FULL POST

Wednesday, October 23, 2013

Sticky bit concept and implementation                                      Check CPU usage of file system

SetUID:

SetUID is a set User ID upon execution. We can identify SetUID bit is set or not in permissions of file by long listing the details of file as below.

[linuxconcepts@localhost test]$ cat > setuid.sh
#!/bin/sh
echo "SET USER ID BIT";
date
[linuxconcepts@localhost test]$
[linuxconcepts@localhost test]$ ls -l setuid.sh
-rw-rw-r--. 1 linuxconcepts linuxconcepts 39 Oct 23 12:08 setuid.sh
[linuxconcepts@localhost test]$ chmod 4755 setuid.sh
[linuxconcepts@localhost test]$ ls -l setuid.sh
-rwsr-xr-x. 1 linuxconcepts linuxconcepts 39 Oct 23 12:08 setuid.sh
[linuxconcepts@localhost test]$
//We can set setUID bit by following method as well
[linuxconcepts@localhost test]$ touch setuid1.sh
[linuxconcepts@localhost test]$ ls -l setuid1.sh
-rw-rw-r--. 1 linuxconcepts linuxconcepts 0 Oct 23 13:22 setuid1.sh
[linuxconcepts@localhost test]$ chmod u+s setuid1.sh
[linuxconcepts@localhost test]$ ls -l setuid1.sh
-rwsrw-r--. 1 linuxconcepts linuxconcepts 0 Oct 23 13:22 setuid1.sh
[linuxconcepts@localhost test]$

We can see ‘s’ letter in permission of a setuid.sh file when we change permissions to 4755. We use 4 before actual permission digit to setUID bit to any file.

Benefit: When we set the setUID bit in linux then that script will execute with its owner’s permission. Means if any user is executing that script who have execution permission then it will execute with owner’s permission.

Generally, setUID bit is disabled in most of unix like operating systems because it is unsecure and it gives full access to execute the script.

We can remove setUID bit as follows:

[linuxconcepts@localhost test]$ chmod u-s setuid1.sh
[linuxconcepts@localhost test]$ ls -l setuid1.sh
-rw-rw-r--. 1 linuxconcepts linuxconcepts 0 Oct 23 13:22 setuid1.sh
[linuxconcepts@localhost test]$
SetGID :

SetGID is a set group ID upon execution. It is same as setUID. But setUID is for user and setGID bit is in linux is for group. It can bet set and remove as follows.

[linuxconcepts@localhost test]$ ls -l setuid1.shroup
-rw-rw-r--. 1 linuxconcepts linuxconcepts 0 Oct 23 13:22 setuid1.sh
[linuxconcepts@localhost test]$
[linuxconcepts@localhost test]$ chmod 2755 setuid1.sh
[linuxconcepts@localhost test]$  ls -l setuid1.sh
-rwxr-sr-x. 1 linuxconcepts linuxconcepts 0 Oct 23 13:22 setuid1.sh
[linuxconcepts@localhost test]$ chmod u-s setuid1.sh
[linuxconcepts@localhost test]$ ls -l setuid1.sh
-rwxr-sr-x. 1 linuxconcepts linuxconcepts 0 Oct 23 13:22 setuid1.sh
[linuxconcepts@localhost test]$

Generally SetGID or SetUID bit is set for commands or service commands.

You might be interested in other posts. Have a look on it :

Jinfo command to get details about java process                  Jstat command in Linux
Posted by Machindra Dharmadhikari On 10/23/2013 09:41:00 PM No comments READ FULL POST

Wednesday, July 31, 2013

Interview Questions for Linux Administrator                                             Linux Commands & Tools 

There are many devices or mount points mounted on system. But sometimes, we need to mount these mount points by unique ID. This case generally happens in network because in same network, might have same name mount points on different disks. To avoid this conflict, we will mount the mount points by their block ID which is always unique.

Before doing entry in /etc/fstab file, we need to find block ID of that file. We will do it by following commands as follows:

root@hello:~/myhome/test# blkid /dev/sda1
/dev/sda1: UUID="s91ed12-d675-46bf-a42f-07fgc2313505" TYPE="ext3"
root@hello:~/myhome/test#
root@hello:~/myhome/test# blkid /dev/sda3
/dev/sda3: UUID="k4161839-0b4d-45aa-b4d5-49c76g989628" TYPE="ext3"
root@hello:~/myhome/test#


As per above example, block id will show for only created partitions and we need to provide one parameter for this command and that is partition name.

After this, we can mount file system or partition on operating system with this block ID. It is permanent block id for this partition and it will never change. For each physical partition, there is unique block id for it.
Example of /etc/fstab file configuration by UUID.

# swap was on /dev/sda5 during installation
UUID=72c7301e-239b-44a0-9ccd-41693680d91c none            swap    sw              0       0


If you see in above example, we have used UUID for that device not device or partition name while mounting it in /etc/fstab file.

This method i.e. mounting by block ID is not useful for single home desktop because we will not enterprise grade storage or requirements. 

Chkconfig command in Linux                                                                                   Basic Uses of tar command
Posted by Machindra Dharmadhikari On 7/31/2013 11:48:00 PM No comments READ FULL POST
VI Editor                                                                                                   Useradd Command in Linux

There are many shells which are not coming by default in our operating system. So, that time we need to install it externally by downloading rpm package for Linux, deb package for Solaris, do apt-get for Ubuntu etc. But when we install this shell and somehow it is not working then we need configure it with following steps:

Step 1:

Install shell’s rpm, deb etc. package into operating system.

Step 2:

 Now try to access that shell or try to switch that shell if it is not working then run following steps.

Step 3:

Check configuration file /etc/shells and make entry for that shell like /bin/csh/ or /usr/bin/es or /usr/bin/rc or /bin/rbash etc. If entry is already present then don’t do anything.
But this step has to execute after installation only.

Step 4:

Run following command after making entry  in /etc/shells.

root@hello:~/home/test# add-shell shell-name


add-shell command is used to add shell in kernel. i.e. it updates the kernel information for this shell if it is not present in kernel’s database.

Advanced tricks of Sed command                                          Difference between SAN and NAS
Posted by Machindra Dharmadhikari On 7/31/2013 11:41:00 PM No comments READ FULL POST

Tuesday, July 30, 2013

Crontab in Linux                                                                            Steps to create Logical Volume

Vi editor works as text editor in Linux. We can create, modify, search and replace patterns in a file like these multiple operations, we can do using vi editor. Vi and vim editors are almost same commands but vim is having many advanced features as compared to vi editor. Vim is advanced version of vi editor.

Mostly vi search operation is very useful for us to while editing any file or changing any configuration file. Below are some of the examples of vi/vim editor commands:

Shortcut
Command
Vi filename
Open a file called filename/ we can use absolute path of file here
Esc + i
Insert mode
Esc + :wq
Save and quit
Esc + :q
Quit without save
Esc + :w
Save
Esc + /pattern
It will search pattern in a file and highlight that pattern if found
Esc + dw
Current word delete where cursor points
Esc + dd
Delete current line/ Cuts the current Line
Esc + x
Delete current character
Esc  + P
Paste whatever copied or cut before cursor
Esc + yy
Copy current Line
Esc  + 2yy
Copy current Line and one more immediate line of it
Esc + y$
Copy current line to end of file
Esc + p
Paste after cursor
Esc + q!
Quit and throw away any changes
Esc + ?Pattern
Search backward pattern in Vi editor
Esc + a
Append after cursor
Esc + I
Insert at beginning of Line
Esc + w
Jump word by word/ cursor always remain at beginning of word
Esc + W
Jump word by word
Esc + h
Move left
Esc + j
Move down
Esc + e
Jump to end of words
Esc + b
Jump to backward by words
Esc + B
Jump to backward by words
Esc + 0
Start of Line
Esc + _
Go to the start of Line
Esc  + $
Go to the end of Line
Esc + cc
Change of line
Esc + cw
Change current word
Esc + u
Undo current change
Esc + U
Undo current changes made to the current Line only
Esc + .
Repeat last command in vi editor
Esc + :e filename
Edit a file in a new buffer
Ctrl +ws
Split Windows
Ctrl + wv
Split Windows vertically
Ctrl + ww
Split Windows in Vi editor
Ctrl + wq
Quit windows
Esc + :bn
Go to next buffer
Esc  + :s/Pattern1/Pattern2/g
Replace all pattern1 with pattern2 in vi editor

                

How to recover deleted files in Linux                                                     Shells in Unix/Linux
Posted by Machindra Dharmadhikari On 7/30/2013 10:53:00 AM 2 comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner