Monday, July 7, 2014

Journal Entry 3

Sometimes I like to observe people as they live their busy lives. In Railway Station you will observe people who are happy, sad, dejected,sleepy, restless etc.

There are some who are returning from work, some from a holiday. There are those going to give an exam and there are those who are going to meet their relatives.

You may overhear a conversation, somebody having career ambition, health challenges. Sometimes chitter chatter between two friends. Idle talk of children. Scolding parents, old man giving advice, a teenagers gossip.

Sometimes I cannot hear what they are saying, but seeing the body language you can guess which of the above case does the conversation lie in

Monday, June 30, 2014

Journal Entry 2

1. Verbs : Run, Sing,Dance,Walk,Fly
2.Adverbs : Fast Running, Sweet Singing, Graceful Dancing, Brisk Walking, Majestic Flying

Journal 1 for Online Course in English


1.Nouns:  Building, Car, Trees, Clouds, Road, Birds, Students, Pathway, Basketball Court,Kiosk
2.Adjectives : Tall, Fast, Grey, Long, Enthusiastic, Crowded, Dirty, Colourful, Beautiful

Friday, July 15, 2011

UNIX Diff / Find Command

By : Robert Christopher, Priyanka Catherine Lobo

Introduction

The 'diff' command compares files line by line. This command has a whole range of switches that can be used to compare only elements that are required for us. On the other hand, the 'find' command is used to search for files in a directory, evaluating the filename from left to right.

Example

Let's assume, we have two computer programmers trying to solve sum of two numbers problem simultaneously using two files (sumone.c and sumtwo.c) which are stored in one folder (assignment). We can use the diff / find command of the UNIX shell for controlling the version and also to track changes in the source code file. Although both the commands have similar feel, they are different. We shall first look at examples on the ‘diff’ command and later some examples on the ‘find’ command.

Diff Scenario 1: To see the difference in two files (sumone.c and sumtwo.c).

robertadmin@Robert:~/assignment$ diff sumone.c sumtwo.c

Output: Shows the general differences between sumone.c and sumtwo.c

Diff Scenario 2: To find the author’s name of the files.

robertadmin@Robert:~/assignment$ diff sumone.c sumtwo.c|grep Author

Output: Gives only the Author’s names after extraction from the file.

Diff Scenario 3: To view the files side by side for changes.

robertadmin@Robert:~/assignment$ diff -y sumone.c sumtwo.c

Output: Shows the files side by side for viewing the changes visually.

Diff Scenario 4: To check if difference occurs between two files.

robertadmin@Robert:~/assignment$ diff -q sumone.c sumtwo.c

Output: Gives a quick check of the occurrence of differences in files.

Find Scenario 1: To find the files in a directory (assignment).

robertadmin@Robert:~$ find ./assignment

Output: Shows only the files in the assignment directory.

Find Scenario 2: To find specific type of files.

robertadmin@Robert:~/assignment$ find -type f

Output: Gives only regular type files from the assignment directory.

Find Scenario 3: To find specific file names.

robertadmin@Robert:~/assignment$ find -iname *one.c

Output: Gives all the files ending with one.c case insensitive.

Find Scenario 4: To find the files that are newer than a given file.

robertadmin@Robert:~/assignment$ find -newer sumone.c

Output: Gives the files which were modified more recently than sumone.c file.

SED in Unix

By: - Laxmikant Chandra

Sed: - stand for “stream editor”. Sed is a multipurpose tool which combines the work of several filters. It is derived from ed, the original UNIX editor. Sed performs noninteractive operation on data stream. It uses very few features but has host of features.

Like diff commandsed uses instruction to act on text. Some examples of sed command are as follow

Suppose we have a file named as name.lst containing following data

01|laxmikant chandra |student |christ university

02|Shishir kumar |student |christ university

03|Rohan sharma |emplyee |infosys

04|Makrand ballal |student |christ university

05|laxminarayan |student |christ university

06|john |emplyee |wipro

07|kareem |student |christ university

08|frenk |employee |infosys

09|sophia |student |christ university

10|rocky |student |prsu

I am performing all the commands on the above file.

1.Line addressing:- Here we can use the sed command same as head or tail command to select the first or last lines.

Examples: -

$ sed ‘3q’ name.lst

The above command will return first 3 lines from the name.lst file.

Output:-

01|laxmikant chandra |student |christ university

02|Shishir kumar |student |christ university

03|Rohan sharma |emplyee |infosys

$ sed –n ‘$p’ name.lst

The above command will return last line from the name.lst file.

Output:-

10|rocky |student |prsu

$ sed –n ‘4,9p’ name.lst

The above command will return all the lines from line number 4 to 9.

Output:-

04|Makrand ballal |studdent |christ university

05|laxminarayan |studdent |christ university

06|john |emplyee |wipro

07|kareem |studdent |christ university

08|frenk |employee |infosys

09|sophia |student |christ university

2. Context addressing:- lets specify some patterns to locate lines. The pattern must be bounded by a /.When you specify a single pattern, all lines containing the pattern are selected. It works same as grep command.

Examples: -

$ sed –n ‘/student/p’ name.lst

This command will select all the lines containing student word.

Output:-

01|laxmikant chandra |student |christ university

02|Shishir kumar |student |christ university

04|Makrand ballal |student |christ university

05|laxminarayan |student |christ university

07|kareem |student |christ university

9|sophia |student |christ university

10|rocky |student |prsu

3. Substitution: - Here we can replace the existing pattern in the file with a new pattern.

Examples: -

$ sed ‘s/|/:/’ name.lst | head –n 2

This command will replace all the ‘|’ with ‘:’ and will select first 2 lines from file name.lst.

Output:-

01:laxmikant chandra |student |christ university

02:Shishir kumar |student |christ university

03:Rohan sharma |emplyee |infosys

04:Makrand ballal |student |christ university

05:laxminarayan |student |christ university

06:john |emplyee |wipro

07:kareem |student |christ university

08:frenk |employee |infosys

09:sophia |student |christ university

10:rocky |student |prsu

$ sed ‘1,5s/student/employee/’ name.lst

The above command will replace ‘student’ with ‘employee’ in first 5 lines in file name.lst.

Output:-

01|laxmikant chandra |employee |christ university

02|Shishir kumar |employee |christ university

03|Rohan sharma |emplyee |infosys

04|Makrand ballal |employee |christ university

05|laxminarayan |employee |christ university

06|john |emplyee |wipro

07|kareem |student |christ university

08|frenk |employee |infosys

09|sophia |student |christ university

10|rocky |student |prsu

$ sed ‘s/^/L/’ name.lst | head -2

This command will add ‘L’ at the staring of each line and will select first 2 lines form the file name.lst.

Output:-

L01|laxmikant chandra |student |christ university

L02|Shishir kumar |student |christ university

4. Deleting lines: - using sed we can delete specific lines.

Examples: -

$ sed ‘1d’ name.lst

This command will delete the 1st line from name.lst file.

Output:-

02|Shishir kumar |student |christ university

03|Rohan sharma |emplyee |infosys

04|Makrand ballal |student |christ university

05|laxminarayan |student |christ university

06|john |emplyee |wipro

$ sed ‘d’ name.lst

It will delete all the lines from name.lst.

Output:-

5. Inserting lines: - We can insert new lines before specific line.

Examples: -

$ sed ‘/01/i\NAME LIST’ name.lst | head -5

The above command will insert ‘Hello’ just before the line starting with ‘bat’ in uniq.sh file and will select first 5 lines.

Output:-

NAME LIST

01|laxmikant chandra |student |christ university

02|Shishir kumar |student |christ university

03|Rohan sharma |emplyee |infosys

04|Makrand ballal |student |christ university

PS in Unix

By Jwalitha N J, Divya Monisha

Syntax : ps [options]

Ps is used to list all the active process. It list the process ID, parent processs ID, user ID, name, terminal.

There are various options that could be given along the ps command such as

To list simple process

Ps –A or ps-e,

Ps –a

Ps T

Ps r

Ps f

To list standard process

Ps –ef

Ps –eF

Ps –ely

To list BSD format

Ps –aux

Ps aux

To list root process ps –u root

To list threads ps -eLF


Syntax: ps [options]

Definition: ps lists the information of active process.

There are various options that could be given in ps , they are as follows

1. ps

When ps alone is executed at the Linux terminal the output generated is

PID TTY TIME CMD

5839 pts/2 00:00:00 bash

5885 pts/2 00:00:00 ps

Here bash is the name of the working terminal and the process that currently running is man ps. Hence here the list has two processes with process-id(PID),file name of the terminal(tty),TIME and CMD

2. ps –A or ps –e

Selects all the process. The output contains PID,TTY,TIME and CMD

3. ps – a

Selects all the process except the process associated with the terminal.

PID TTY TIME CMD

5849 pts/0 00:00:00 man

5858 pts/0 00:00:00 less

5897 pts/2 00:00:00 ps

4. ps –d

Select all process except session leaders. Session leader is one that creates another session.

5. ps r

Selects only running process.

PID TTY STAT TIME COMMAND

5685 pts/0 R+ 0:00 ps r

6. ps T

Selects those process that are associated with the terminal

PID TTY STAT TIME COMMAND

5637 pts/0 Ss 0:00 bash

5702 pts/0 R+ 0:00 ps t

Here bash is the name the working terminal and the process that is associated with bash is ps t command that is currently running.

There are options that displays files in particularformat such as standard format and BSD format

To display standard format process

1. ps -e : selection of all process.

2. Ps –ef

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 19:56 ? 00:00:00 /sbin/init

root 2 0 0 19:56 ? 00:00:00 [kthreadd]

root 3 2 0 19:56 ? 00:00:00 [ksoftirqd/0]

root 4 2 0 19:56 ? 00:00:00 [kworker/0:0]

3. ps -eF

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 19:56 ? 00:00:00 /sbin/init

root 2 0 0 19:56 ? 00:00:00 [kthreadd]

root 3 2 0 19:56 ? 00:00:00 [ksoftirqd/0]

root 4 2 0 19:56 ? 00:00:00 [kworker/0:0]

4. ps -ely

S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD

S 0 1 0 0 80 0 1812 730 poll_s ? 00:00:00 init

S 0 2 0 0 80 0 0 0 kthrea ? 00:00:00 kthreadd

S 0 3 2 0 80 0 0 0 run_ks ? 00:00:00 ksoftirqd/0

S 0 4 2 0 80 0 0 0 worker ? 00:00:00 kworker/0:0

To display process of BSD format

1. ps -aux

This selects process those associated with a particular user.

PID TTY STAT TIME COMMAND

1 ? Ss 0:00 /sbin/init

2 ? S 0:00 [kthreadd]

3 ? S 0:00 [ksoftirqd/0]

2. ps aux

This selects all the process with the complete details The difference in aux and -aux is that , in -aux the user name is given example –ausylar.If that user does not exists then the command is treated as aux displaying all the process.

To get information on threads we use the options as

1. ps -eLf

Example:

UID PID PPID LWP C NLWPSZ RSS PSR STIME TTY TIME CMD

root 1 0 1 0 1 549 704 0 19:51 ? 00:00:01 init [5]

root 2 0 2 0 1 0 0 1 19:51 ? 00:00:00 [kthreadd]

sylar 5795 5637 5795 0 1 650 852 0 20:11 pts/0 00:00:00 ps -eLF

Sample program

ps // to list current working process.

#ps –e

ps u // to list process that run as root

ps -u root

ps -eopid // to list all process PID.

ps -p 2454 // to list the name of the process with PID 2454.

Output

// output for ps

PID TTY TIME CMD

5927 pts/3 00:00:00 bash

6006 pts/3 00:00:00 sh

6007 pts/3 00:00:00 ps

// output for ps u

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

sylar 5637 0.0 0.0 5028 2272 pts/0 Ss 19:53 0:00 bash

sylar 5652 0.0 0.0 5028 2268 pts/2 Ss 19:53 0:00 bash

sylar 5668 0.0 0.0 4508 1656 pts/2 S+ 19:53 0:00 man ps

sylar 5677 0.0 0.0 3848 996 pts/2 S+ 19:53 0:00 less

sylar 5854 0.0 0.0 2600 868 pts/0 R+ 20:18 0:00 ps u

// output for ps –u root

PID TTY TIME CMD

1 ? 00:00:01 init

2 ? 00:00:00 kthreadd

3 ? 00:00:00 ksoftirqd/0

4 ? 00:00:01 kworker/0:0

6 ? 00:00:00 migration/0

7 ? 00:00:00 watchdog/0

8 ? 00:00:00 migration/1

10 ? 00:00:00 ksoftirqd/1

12 ? 00:00:00 watchdog/1

13 ? 00:00:00 migration/2

// output for ps -eopid

PID

1

2

3

4

6

7

.. 6008

//output for ps –p 2454

PID TTY TIME CMD

2454 tty5 00:00:00 mingetty