0% found this document useful (0 votes)
78 views4 pages

What Is Unix ?: Grep Command

The Unix operating system acts as an interface between the user and computer. The kernel is the core of the operating system that manages system resources and hardware. Users communicate with the kernel via a shell program that interprets commands and converts them to a language the kernel understands. Unix was developed in 1969 and includes features like multi-user access and multitasking. It organizes all data into files within a tree structure of directories.

Uploaded by

jkl_mm
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views4 pages

What Is Unix ?: Grep Command

The Unix operating system acts as an interface between the user and computer. The kernel is the core of the operating system that manages system resources and hardware. Users communicate with the kernel via a shell program that interprets commands and converts them to a language the kernel understands. Unix was developed in 1969 and includes features like multi-user access and multitasking. It organizes all data into files within a tree structure of directories.

Uploaded by

jkl_mm
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

What is Unix ?

The UNIX operating system is a set of programs that act as a link between the computer and the
user.The computer programs that allocate the system resources and coordinate all the details of
the computer's internals is called the operating system or kernel.

Users communicate with the kernel through a program known as the shell. The shell is a
command line interpreter; it translates commands entered by the user and converts them into a
language that is understood by the kernel.

 Unix was originally developed in 1969 by a group of AT&T employees at Bell Labs,
including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.
 There are various Unix variants available in the market. Solaris Unix, AIX, UP Unix and
BSD are few examples. Linux is also a flavour of Unix which is freely available.
 Several people can use a UNIX computer at the same time; hence UNIX is called a
multiuser system.
 A user can also run multiple programs at the same time; hence UNIX is called
multitasking.

Unix Architecture:
The main concept that unites all versions of UNIX is the following four basics:

 Kernel: The kernel is the heart of the operating system. It interacts with hardware and
most of the tasks like memory management, tash scheduling and file management.
 Shell: The shell is the utility that processes your requests. When you type in a command
at your terminal, the shell interprets the command and calls the program that you want.
The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell
are most famous shells which are available with most of the Unix variants.
 Commands and Utilities: There are various command and utilities which you would use
in your day to day activities. cp, mv, cat and grep etc. are few examples of commands
and utilities. There are over 250 standard commands plus numerous others provided
through 3rd party software. All the commands come along with various optional options.
 Files and Directories: All data in UNIX is organized into files. All files are organized
into directories. These directories are organized into a tree-like structure called the
filesystem.

Grep command

The grep utility is one of the most useful filters in Unix. Grep searches line-by-line
for a specified pattern, and outputs any line that matches the pattern.
The basic syntax for the grep command is
grep [-options] pattern [file].

If the file argument is omitted, grep will read from standard input. It
is always best to enclose the pattern within single quotes, to prevent the shell from
misinterpreting the command.
The grep utility recognizes a variety of patterns, and the pattern specification
syntax was taken from the vi editor. Here are some of the characters you can use to
build grep expressions:
l The caret (^) matches the beginning of a line.
l The dollar sign ($) matches the end of a line.
l The period (.) matches any single character.
l The asterisk (*) matches zero or more occurrences of the previous character.
l The expression [a-b] matches any characters that are lexically between a and b.

Note that some of the pattern matching characters are also shell meta characters. If
you use one of those characters in a grep command, make sure to enclose the
pattern in single quote marks, to prevent the shell from trying to interpret them.

EXAMPLE: Type the command


grep 'jon' /etc/passwd
to search the /etc/passwd file for any lines containing the string "jon".

Killing processes
Occasionally, you will find a need to terminate a process. The Unix shell provides
a utility called kill to terminate processes. You may only terminate processes that
you own (i.e., processes that you started).

The syntax for the kill command is


kill [-options] process-ID.

To kill a process, you must first find its process ID number using the ps command.
Some processes
refuse to die easily, and you can use the "-9" option to force termination of the job.

EXAMPLE: To force termination of a job whose process ID is 111, enter the


command
kill -9 111
Interaction and Job Control
When you log in to a Unix system, the kernel starts a shell for you, and connects
the shell to your terminal. When you execute a command from the shell, the shell
creates a child process to execute the command, and connects the child process to
your terminal. By connecting the child process to your terminal, the shell allows
you to send input to the child process, and receive output from it.

When the child process finishes, the shell regains access to the terminal, redisplays
the shell prompt, and waits for your next command.
Any task that requires you to actively participate (like word processing) must be in
the foreground to run. Such jobs, termed "interactive," must periodically update the
display, and accept input from you, and so require access to the terminal interface.
Other jobs do not require you to participate once they are started. For example, a
job that sorts the contents of one file and places the results in another file, would
not have to accept user commands, or write information to the screen while it runs.
Some Unix shells allow such non interactive jobs to be disconnected from the
terminal, freeing the terminal for interactive use.

Note that it is even possible to log out, and leave a background process running.
Unfortunately, there is no way to reconnect a background job to the terminal after
you've logged out.
Jobs that are disconnected from the terminal for input and output are called
"background" jobs. You can have a large number of background jobs running at
the same time, but you can only have one foreground job. That is because you only
have one screen, and one keyboard at your terminal.

Background and foreground jobs


The process that is connected to the terminal is called the foreground job. A job is
said to be in the foreground because it can communicate with the user via the
screen, and the keyboard.
A Unix process can be disconnected from the terminal, and allowed to run in the
background.
Because background jobs are not connected to a terminal, they cannot
communicate with the user. If the background job requires interaction with the
user, it will stop, and wait to be reconnected to the terminal.
Jobs that do not require interaction from the user as they run(like sorting a large
file) can be placed in the background, allowing the user to access the terminal, and
continue to work, instead of waiting for a long job to finish.
echo
The echo command prints out whatever is given to it as an argument. For example,
if you give the command echo hello, you will see hello print to your screen.
echo is primarily useful for providing output in shell programs and printing out
the values of variables; we’ll discuss these topics in later chapters. You’ve used
echo to determine the shell environment you’re using, by typing echo $SHELL.

What Is ed?
ed is a line editor. There are two major types of text editors in the Unix world: line
editors and full-screen editors. (We discuss full-screen editors in Chapter 17: “The
vi Editor.”) When you edit a file with a line editor like ed, you must do so one
line at a time. In contrast, when you use a full-screen editor, you can work on
multiple lines at once. Although line editors are extremely cumbersome, they are
better than nothing. There is enough functionality in a line editor to get your
work done; it’s simply not as easy as it would be with more advanced tools.
ed operates in two modes: input mode and edit mode. (ed also has a command
mode, which is used to manipulate the program until you are ready to work
with text.) As their names imply, input mode is used to insert text into a file, and
edit mode is used to alter the entered text. In later chapters of this part of the
book, you’ll see other editors that use the input and edit mode concepts, even
though they are not line editors.

You might also like