0% found this document useful (0 votes)
5 views

operating system module

Uploaded by

shinasar123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

operating system module

Uploaded by

shinasar123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

OPERATING SYSTEM

MODULE II
Linux Shell Programming: Introduction – Shells available in Unix: Bourne shell (sh), C shell
(csh), TC shell (tcsh), Korn shell (ksh), Bourne Again SHell (bash). Bash: special characters –
getting help – man pages – Linux Directory Layout – Command for Navigating the Linux
Filesystems: pwd, cd, ls, file, cat, cp, mv, mkdir, rmdir, whereis – Piping and Redirection -
Informational Commands: ps, w, id, free – clear, echo, more. File permissions – Setting
Permissions – Making a file executable. Creating shell programs: comments, variables,
operators (arithmetic, relational, logical) – single and double quotes - read – echo – test -
conditional commands, iterative commands – break – continue - evaluating expressions using
expr, bc – strings – grep – arrays.

1. What is a Shell, and Why do we need them?


Whenever a user logs in to the system or opens a console window, the kernel runs a new shell
instance.
The kernel is the heart of any operating system. It is responsible for the control management, and
execution of processes, and to ensure proper utilization of system resources.
A shell is a program that acts as an interface between a user and the kernel. It allows a user to give
commands to the kernel and receive responses from it. Through a shell, we can execute programs and
utilities on the kernel. Hence, at its core, a shell is a program used to execute other programs on our
system.

2.Different Types of Shells in Linux

1. The Bourne Shell (sh)


Developed at AT&T Bell Labs by Steve Bourne, the Bourne shell is regarded as the first UNIX shell
ever. It is denoted as sh. It gained popularity due to its compact nature and high speeds of operation.
This is what made it the default shell for Solaris OS. It is also used as the default shell for all Solaris
system administration scripts.
The Bourne shell has some major drawbacks.

• It doesn’t have in-built functionality to handle logical and arithmetic operations.


• Also, unlike most different types of shells in Linux, the Bourne shell cannot recall previously used
commands.
• It also lacks comprehensive features to offer a proper interactive use.

The complete path-name for the Bourne shell is /bin/sh and /sbin/sh. By default, it uses the
prompt # for the root user and $ for the non-root users.
2. The GNU Bourne-Again Shell (bash)
More popularly known as the Bash shell, the GNU Bourne-Again shell was designed to be compatible
with the Bourne shell. It incorporates useful features from different types of shells in Linux such as
Korn shell and C shell.
It allows us to automatically recall previously used commands and edit them with help of arrow keys,
unlike the Bourne shell.
The complete path-name for the GNU Bourne-Again shell is /bin/bash. By default, it uses the
prompt bash-VersionNumber# for the root user and bash-VersionNumber$ for the non-root users.
3. The C Shell (csh)
The C shell was created at the University of California by Bill Joy. It is denoted as csh. It was
developed to include useful programming features like in-built support for arithmetic operations and a
syntax similar to the C programming language.
Further, it incorporated command history which was missing in different types of shells in Linux like
the Bourne shell. Another prominent feature of a C shell is “aliases”.
The complete path-name for the C shell is /bin/csh. By default, it uses the prompt hostname# for the
root user and hostname% for the non-root users.
4. The Korn Shell (ksh)
The Korn shell was developed at AT&T Bell Labs by David Korn, to improve the Bourne shell. It is
denoted as ksh. The Korn shell is essentially a superset of the Bourne shell.
Besides supporting everything that would be supported by the Bourne shell, it provides users with new
functionalities. It allows in-built support for arithmetic operations while offering interactive features
which are similar to the C shell.
The Korn shell runs scripts made for the Bourne shell, while offering string, array and function
manipulation similar to the C programming language. It also supports scripts which were written for
the C shell. Further, it is faster than most different types of shells in Linux, including the C shell.
The complete path-name for the Korn shell is /bin/ksh. By default, it uses the prompt # for the root
user and $ for the non-root users.
5. The Z Shell (zsh)
The Z Shell or zsh is a sh shell extension with tons of improvements for customization. If you want a
modern shell that has all the features a much more, the zsh shell is what you’re looking for.
Some noteworthy features of the z shell include:

• Generate filenames based on given conditions


• Plugins and theming support
• Index of built-in functions
• Command completion
• and many more…

Let us summarise the different shells in Linux which we discussed in this tutorial in the table below.

Complete path- Prompt for root Prompt for non root


Shell
name user user

Bourne shell (sh) /bin/sh and /sbin/sh # $

GNU Bourne-Again shell bash-


/bin/bash bash-VersionNumber$
(bash) VersionNumber#

C shell (csh) /bin/csh # %

Korn shell (ksh) /bin/ksh # $

Z Shell (zsh) /bin/zsh <hostname># <hostname>%

3.which Linux command is used to remove an empty directory


1. To remove an empty directory, use either rmdir or rm -d followed by the directory name: rm -d
dirname rmdir dirname.
2. To remove non-empty directories and all the files within them, use the rm command with the -r
(recursive) option: rm -r dirname

4.what is the default umask value in linux


Octal umask Mode 022 And 002
1. The default umask 002 used for normal user. With this mask default directory permissions are
775 and default file permissions are 664.
2. The default umask for the root user is 022 result into default directory permissions are 755 and
default file permissions are 644.
3. For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-
rw).
In short,

1. A umask of 022 allows only you to write data, but anyone can read data.
2. A umask of 077 is good for a completely private system. No other user can read or write your data
if umask is set to 077.
3. A umask of 002 is good when you share data with other users in the same group. Members of your
group can create and modify data files; those outside your group can read data file, but cannot
modify it. Set your umask to 007 to completely exclude users who are not group members.

How Do I Calculate umasks?


The octal umasks are calculated via the bitwise AND of the unary complement of the argument using
bitwise NOT. The octal notations are as follows:

▪ Octal value : Permission


▪ 0 : read, write and execute
▪ 1 : read and write
▪ 2 : read and execute
▪ 3 : read only
▪ 4 : write and execute
▪ 5 : write only
▪ 6 : execute only
▪ 7 : no permissions
Now, you can use above table to calculate file permission. For example, if umask is set to 077, the
permission can be calculated as follows:

Bit Targeted at File permission


0 Owner read, write and execute
7 Group No permissions
7 Others No permissions
5.Give the different types of shells available in linux
Bourne Shell (sh)
Bourne-Again Shell (bash)
Korn Shell (ksh)

6.write a shell script to list all users available in /etc/passwd file in linux
u = cat/etc/passwd
echo "The list off all users are $u"

7.what is the use of ls command in linux?explain different options of ls command


The ls command is used to list files or directories in Linux and other Unix-based operating systems

ls option Description

ls -a In Linux, hidden files start with. (dot) symbol and they are not visible in the
regular directory. The (ls -a) command will enlist the whole list of the current
directory including the hidden files.

ls -l It will show the list in a long list format.

ls -lh This command will show you the file sizes in human readable format. Size of
the file is very difficult to read when displayed in terms of byte. The (ls -lh)
command will give you the data in terms of Mb, Gb, Tb, etc.

ls -lhS If you want to display your files in descending order (highest at the top)
according to their size, then you can use (ls -lhS) command.

ls -l - -block-size=[SIZE] It is used to display the files in a specific size format. Here, in [SIZE] you can
assign size according to your requirement.

ls -d */ It is used to display only subdirectories.

ls -g or ls -lG With this you can exclude column of group information and owner.
ls -n It is used to print group ID and owner ID instead of their names.

ls --color=[VALUE] This command is used to print list as colored or discolored.

ls -li This command prints the index number if file is in the first column.

ls -p It is used to identify the directory easily by marking the directories with a


slash (/) line sign.

ls -r It is used to print the list in reverse order.

ls -R It will display the content of the sub-directories also.

ls -lX It will group the files with same extensions together in the list.

ls -lt It will sort the list by displaying recently modified filed at top.

ls ~ It gives the contents of home directory.

ls ../ It give the contents of parent directory.

ls --version It checks the version of ls command.


8.give a detailed account on linux directory layout
9.Explain Unix File System Commands

#1) touch: Create a new file or update its timestamp.


• Syntax: touch [OPTION]…[FILE]
• Example: Create empty files called ‘file1’ and ‘file2’
• $ touch file1 file2
#2) cat: Concatenate files and print to stdout.
• Syntax: cat [OPTION]…[FILE]
• Example: Create file1 with entered cotent
• $ cat > file1
• Hello
• ^D
#3) cp: Copy files
• Syntax: cp [OPTION]source destination
• Example: Copies the contents from file1 to file2 and contents of file1 is retained
• $ cp file1 file2
#4) mv: Move files or rename files
• Syntax: mv [OPTION]source destination
• Example: Create empty files called ‘file1’ and ‘file2’
• $ mv file1 file2
#5) rm: Remove files and directories
• Syntax: rm [OPTION]…[FILE]
• Example: Delete file1
• $ rm file1
#6) mkdir: Make directory
• Syntax: mkdir [OPTION] directory
• Example: Create directory called dir1
• $ mkdir dir1
#7) rmdir: Remove a directory
• Syntax: rmdir [OPTION] directory
• Example: Create empty files called ‘file1’ and ‘file2’
• $ rmdir dir1
#8) cd: Change directory
• Syntax: cd [OPTION] directory
• Example: Change working directory to dir1
• $ cd dir1
#9) pwd: Print the present working directory
• Syntax: pwd [OPTION]
• Example: Print ‘dir1’ if a current working directory is dir1
• $ pwd

You might also like