operating system module
operating system module
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.
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:
Let us summarise the different shells in Linux which we discussed in this tutorial in the table below.
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.
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"
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 -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 -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 -li This command prints the index number if file is in the first column.
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.