Experiment No - 4 Problem Definition:: - F Ls /' Ls - R
Experiment No - 4 Problem Definition:: - F Ls /' Ls - R
Experiment No - 4 Problem Definition:: - F Ls /' Ls - R
EXPERIMENT NO - 4
PROBLEM DEFINITION :
Linux commands are executable binary files which can be ran to perform certain tasks, like for
example listing the files in a directory running an entire graphical application.
2. Cat and tac Command:- Cat command is a well known Unix utility that reads files
sequentially. Writing them to conventional output.Tac (that is cat backwards)
concatenates every record to traditional output much like the cat command. However in
opposite: line-by means of-line, printing the last line first.
14
AKSHIT RANA
16BCS1204
OS(CSP-210)
3. Sort command:- sort is a simple and very useful command which will rearrange the
lines in a text file so that they are sorted, numerically and
alphabetically.
4. Head and Tail command:- The Linux head and tail commands are very similar.The
head command command prints lines from the beginning of a file (head),and the tail
command prints lines from the end of files.
15
AKSHIT RANA
16BCS1204
OS(CSP-210)
charactersr in a file.
6. The grep command:- As grep prints out lines from the file by the pattern / string you had
given.When you do the following export you will get the highlighting of the matched
searches. When you want to display the lines which does not matches the given
string/pattern, use the option grep -v .
16
AKSHIT RANA
16BCS1204
OS(CSP-210)
EXPERIMENT:-6
Problem definition: Shell programming is a basic skill that every UNIX System Administrator
should have. The Systems Administrator must be able to read and write shell programs because
there are many tasks that can and should be quickly automated by using shell programs,
many software products come with install scripts that have to be modified for your
system before they will work.
Simply put, a shell program (sometimes called a shell script) is a text file that contains standard
UNIX and shell commands. Each line in a shell program contains a single UNIX command
exactly as if you had typed them in yourself. The difference is that you can execute all the
commands in a shell program simply by running the shell program (rather than typing all the
commands within).
Shell programs are interpreted and not compiled programs. This means when you run a shell
program a child shell is started. This child shell reads each line in the shell program and carries
out the command on that line. When it has read all the commands the child shell finishes.
comments,
variables,
conditional commands, and
repeated action commands.
17
AKSHIT RANA
16BCS1204
OS(CSP-210)
The next step is to add the commands you wish the shell program to perform. The commands can
be any standard UNIX or shell command. Of course any shell commands you use must be
supported by the shell that will interpret your shell program.
Once you've added all the commands you can then save the file. In order to execute a shell
program both the read and execute permissions must be set. By default when you save a text file
the execute file permission will not be set. You will have to set this manually.
By default a shell reads commands from standard input. This is the mode of operation you are
use to. It is also possible for the shell to read commands from a file. For example
unx1:~$ sh files
will start a new shell but rather than reading commands from standard input the shell will read its
commands from the file called files. (created in the example in the previous section).
The other method to execute a shell program is to enter its name in the same way as you would
execute any other command. For example to run the files shell script you would simply type
unx1:~$ files
A common mistake for many new shell programmers is to create a shell program called test and
then wonder why it doesn't work as expected.
/usr/bin/which test
Do you see the problem? There is already a command called test and it is the command that is
usually found first when you try to run a command called test. Use which when you have a
question as to whether you are running the correct shell program.
At the end of your script, use "return N" to give a specific return value, as in this script:
#!/usr/local/bin/ksh
print "Hello World"
return 0
You can use the built-in variable $? to access the exit status of the previously run
command. If the above script were HelloScript:
$ HelloScript
$ print $?
0
A Simple Example
$ gohome
19
AKSHIT RANA
16BCS1204