Introduction To Shell Programming: Operating System Lab
Introduction To Shell Programming: Operating System Lab
Introduction To Shell Programming: Operating System Lab
Lab 2
Introduction to Shell Programming
Part I. Changing file mode. Only the owner of a file can use chmod (change file mode) to
change the permission of a file.
1. Create a text file by redirecting the output of l s - 1 command into a text file called files.txt.
i.e. ls - 1 > files . txt .
2. Type ls –l files.txt to check the permissions of this file. (Permissions consist of 10 characters
i.e. - r w - r - - r - - . The first character indicates the file type and the rest indicate the file
access
modes for user, group and all the others respectively)
3. Try the following commands and then observe the difference in the permissions.
Part II. Displaying information: The echo command can be used to display messages. It
displays its arguments on your terminal.
3. echo command can be used to display text and the values of the shell variables. To access
the value stored in a shell variable, you must precede the name of the variable with a $. Set
age to 25. i.e. age = 25 or age = ”25 ” .
echo ~
Part III.
1. Write a simple shell script to display number of users in the system by using p i c o utility
as shown below and save it as won.
2. You can use sh command to execute script files. To run won script, type s h w o n .
Carefully read the description of the corresponding lab. The lab outline contains background for
the lab and directions for doing the lab procedure. There may also be handouts or other materials
Submitted By: Ali Murad
Submitted To: Muhib Khan
Operating System Lab
you have access to. By the help of a Live CD of Ubuntu you can study to the corresponding lab
without making any changes to your machine. Answers of the preliminary Lab Questions must
be handled at the beginning of the laboratory. A full printable version of this sheet is available
online.
NAME
chmod - change file mode bits
SYNOPSIS
chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...
DESCRIPTION
This manual page documents the GNU version of chmod. chmod changes the
file mode bits of each given file according to mode, which can be
either a symbolic representation of changes to make, or an octal number
representing the bit pattern for the new mode bits.
The operator + causes the selected file mode bits to be added to the
existing file mode bits of each file; - causes them to be removed; and
= causes them to be added and causes unmentioned bits to be removed
except that a directory's unmentioned set user and group ID bits are
not affected.
The letters rwxXst select file mode bits for the affected users: read
(r), write (w), execute (or search for directories) (x), execute/search
only if the file is a directory or already has execute permission for
some user (X), set user or group ID on execution (s), restricted dele‐
tion flag or sticky bit (t). Instead of one or more of these letters,
you can specify exactly one of the letters ugo: the permissions granted
to the user who owns the file (u), the permissions granted to other users who are
members of the file's group (g), and the permissions
granted to users that are in neither of the two preceding categories
(o).
chmod never changes the permissions of symbolic links; the chmod system
call cannot change their permissions. This is not a problem since the
permissions of symbolic links are never used. However, for each sym‐
bolic link listed on the command line, chmod changes the permissions of
the pointed-to file. In contrast, chmod ignores symbolic links encoun‐
tered during recursive directory traversals.
NAME
dash — command interpreter (shell)
SYNOPSIS
dash [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name] [+o option_name]
[command_file [argument ...]]
dash -c [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name] [+o option_name]
command_string [command_name [argument ...]]
dash -s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name] [+o option_name]
[argument ...]
DESCRIPTION
dash is the standard command interpreter for the system. The current version of dash is
in the process of being changed to conform
with the POSIX 1003.2 and 1003.2a specifications for the shell. This version has many
features which make it appear similar in some
respects to the Korn shell, but it is not a Korn shell clone (see ksh(1)). Only features
designated by POSIX, plus a few Berkeley
extensions, are being incorporated into this shell. This man page is not intended to be a
tutorial or a complete specification of the
shell.
4. Write the command necessary to make script file “xyz” an executable file for the user?
echo command can be used to display text and the values of the shell variables.
Signature >:_________________