Search This Blog

Monday, January 23, 2012

Sort

Sort is often used to organize the output in asc/desc order.

Here are prominent options used with sort.

-n:sort in numeric order
-r:sort in reverse order
-t:Used to specify delimiter
-k:used to specify field number.

Lets explore the option with example.


Sort all users according to their names.
#sort -t ":" -k 1 /etc/passwd
Sort all users according to uid.
#sort -t ":" -k 3 -n /etc/passwd

Reverse sort above two queries .
#sort -t ":" -k 1 -r /etc/passwd
#sort -t ":" -k 3 -n -r /etc/passwd

Thursday, January 19, 2012

VI editor.

This is the most basic and widely used linux utility for editing the text files in linux.(You may consider it as notepad in windows).

However it has a little complex way of editing but once you are familiarize with the command its no difficult .

Before start using VI editor ,you must learn the 3 modes of vi editor.
1)Command mode.
2)Insert mode.
3)Last line mode.

Lets explore them one by one.

Create a file .

# touch File1.txt

Now Open it using vi .

#vi File1.txt

Now try typing letters such as 'b','c','d'
What did you notice?
You were not able to type any of above characters this is not limited to just above 3 characters infact most of the characters are not getting typed when you open the editor.
Why?
You are not yet in Insert mode.

How to go into Insert mode then?
ok lets start from beginning .
press Escape character on keyboard.
type
:q

you are back to terminal again.
Open the file again
#vi File1.txt

Press 'i' ,You are now in insert mode and can type anything you wish.

just type below characters in the file.

This is my first usage of vi editor.
I know its complex but i will learn it soon.

press Escape character in keyboard
Now type
:wq

What did you do ?
You just saved and closed to file to return back to terminal.
What ever you enter after typing ':' are considered as Last line commands .
They are useful for saving file,quite the file and other tasks.
e.g.
w:saving the file
q:quit the file





Questions and Answers :

How to go to End or Beginning of file in VI editor..?
Ans : Beginning and end of file, i.e. :0 and :$  

How to visit specific line of the file?

Grep command comparison with vi string find....

String replacement.
#
How to search a specific string in VI editor?

How to delete a line ? 

Set command 

Tuesday, January 17, 2012

Linux EMail Services.

Typically Email System is divided in 3 Major parts.

1) MUA (Mail user agent)
2) MDA (Mail Delivery agent)
3) MTA (Mail Transfer agent)


MUA can be cosidered as mail client used for reading or typing mails for END user.
MUA can be classified in below categories
i) Web based E.g Zimbra, IMP
ii) GUI based E.g Thunderbird,Evolution(redhat 6 comes with this )
iii) Console based E.g mutt

MDA takes care of all receiving mail. it delivers it to a separate mail spool until the MUA picks it up for END user.This is usually refered as Local delivery agent as this makes more sense.
It works locally .It moves mails locally.When MTA transfer mail to destination MDA puts that in a mailbox.
MDA work typically involves sorting the incoming mails to directories, Identifying spam mail e.t.c


E.g .
There is only one MDA program which is  procmail.

MTA transfers mails from one to another servers until it reaches to its destination.

E.g
sendmail,pop,IMAP,postfix

There are two Major type of Mail Programs used in Linux.
1)Sendmail 2)Postfix

Sendmail was the default mail program for Most of linux and redhat distributions but due to added features in postfix trend is now changing .RHEL6 comes bundled with postfix as default mail program.

To know what message transfer agent (MTA) you are using?
This can be done using following bash
#ps -ef| grep -iE "sendmail|postfix|exim|courier|james|lotus|qmail|xmail|postmaster"

Friday, January 6, 2012

/etc/skel

/etc/skel is a directory where you place all files that you want to be added to a user’s home directory .


For example :
Create readme.txt file under /etc/skel directory.
#touch readme.txt


Now create new user
#mkuser test
#passwd test

now navigate to home directory of the test user.

#cd /home/test/
# ls -ltr
total 0
-rw-r--r-- 1 test test 0 Jan 6 16:03 readme.txt

(Note:Whatever files that are created under /etc/skel are only get copied to new users home path. it will not be copied to existing users home path)

Thursday, January 5, 2012

Determine actual size of sparse file.

Use below command to get actual size of the file.
Below command is useful to determine the file created with sparse mechanism.

#du -h --apparent-size

Even ls is used to determine the same but du is much more flexible when used on shares containing sparse files scattered across different directories with in the share.