Bos Unit 5
Bos Unit 5
3. Standard library
Contains a set of procedures, one procedure per system call
These procedures are written in assembly language and used to invoke various system calls from
user program.
4. Standard utility program
All UNIX versions supply OS , system call , large no. of standard program
Program include command processor (shell) ,compilers ,editors ,text processing program, file
manipulation utility a various commands…
Program makes user tasks simpler
User interacts with program, program interacts with OS to get services from OS
5. users
Top most layers
User program come in this layer
They interacts with system either by library procedure to invoke system call or by using utility
program such as shell
Kernel
Main service of OS :
o process management , memory management ,file system management ,I/O management
Only one kernel in the system
Commands: pwd, cd, mkdir, rmdir, ls, cat, cp, rm, mv, wc, split, cmp, comm, diff,
head, tail, grep, sort
1. pwd Command
The pwd command is used to display the location of the current working directory.
Syntax: pwd
Output:
2. mkdir Command
The mkdir command is used to create a new directory under any directory.
Prepared By: Department of Computer Engineering Page 3
Subject Name: Basics of Operating System Unit No: 05 Subject Code: 4330703
Output:
3. rmdir Command
Output:
4. ls Command
Syntax: ls
Output:
5. cd Command
Output:
6. cat Command
The cat command is a multi-purpose utility in the Linux system. It can be used to create a file, display content
of the file, copy the content of one file to another file, and more.
Press "CTRL+ D" keys to save the file. To display the content of the file, execute it as follows:
Output:
7. rm Command
Output:
8. cp Command
Output:
9. mv Command
The mv command is used to move a file or a directory form one location to another location.
Output:
The head command is used to display the content of a file. It displays the first 10 lines of a file.
Output:
The tail command is similar to the head command. The difference between both commands is that it displays
the last ten lines of the file content. It is useful for reading the error message.
Output:
12.grep Command
The grep is the most powerful and used filter in a Linux system. The 'grep' stands for "global regular
expression print." It is useful for searching the content from a file. Generally, it is used with the pipe.
Output:
The 'comm' command is used to compare two files or streams. By default, it displays three columns, first
displays non-matching items of the first file, second indicates the non-matching item of the second file, and the
third column displays the matching items of both files.
Output:
13. tr Command
Prepared By: Department of Computer Engineering Page 7
Subject Name: Basics of Operating System Unit No: 05 Subject Code: 4330703
The tr command is used to translate the file content like from lower case to upper case.
Output:
14. wc Command
The wc command is used to count the lines, words, and characters in a file.
Output:
Output:
The vi editor is elaborated as visual editor. It is installed in every Unix system. In other words, it is available
in all Linux distros. It is user-friendly and works same on different distros and platforms. It is a very
powerful application. An improved version of vi editor is vim.
o Command Mode: In command mode, actions are taken on the file. The vi editor starts in command
mode. Here, the typed words will act as commands in vi editor. To pass a command, you need to be in
command mode.
o Insert Mode: In insert mode, entered text will be inserted into the file. The Esc key will take you to the
command mode from insert mode.
By default, the vi editor starts in command mode. To enter text, you have to be in insert mode, just
type 'i' and you'll be in insert mode. Although, after typing i nothing will appear on the screen but you'll be
in insert mode. Now you can type anything.
To exit from insert mode press Esc key, you'll be directed to command mode.
Commands Action
:w Save
:q Quit
To exit from vi, first ensure that you are in command mode. Now, type :wq and press enter. It will save and quit vi.
Now we have developed an understanding of the command-line arguments in Linux. Now it’s time to use this
knowledge for practical application of the netstat command.
For this tutorial, we will go over an example to learn how to use the command-line arguments in your shell
script.
First, we will create a shell script to demonstrate the working of all the reserved variables which we discussed in
the previous section. Use nano or any preferred editor of your choice and copy the following.
This is the shell script which we plan to use for this purpose.
#!/bin/sh
echo "Script Name: $0"
echo "First Parameter of the script is $1"
echo "The second Parameter is $2"
echo "The complete list of arguments is $@"
echo "Total Number of Parameters: $#"
echo "The process ID is $$"
echo "Exit code for the script: $?"
Copy
Once we are done, we will save the script as PositionalParameters.sh and exit our text editor.
Now, we will open the command line on our system and run the shell script with the following arguments.
The script will run with our specified arguments and use positional parameters to generate an output. If you
followed the step correctly, you should see the following screen.
Reading Arguments
Our output shows the correct output by substituting the reserved variables with the appropriate argument when
we called it.
The process was run under the process ID 14974 and quit with the exit code 0.
test and [ …..] is used to evaluate conditional expressions with integers ,strings and file attributes.
test expression
[ expression ]
Integer related test operators:
Expression Result
exp1 -eq exp2 It returns true if exp1 is equal to exp2
exp1 -le exp2 It returns true if exp1 is less than or equal to exp2
Expression Result
-s file True if file exists and its size is greater than zero
Expression Result
2. if ….else
Syntax : if command1
then
command2
else
command3
fi
2. until :
Syntax : until command1
Prepared By: Department of Computer Engineering Page 13
Subject Name: Basics of Operating System Unit No: 05 Subject Code: 4330703
do
commands
done
3. for :
Syntax :
for i in list
do
commands
done