Learning Center
Plans & pricing Sign in
Sign Out



    It is due to persistent encouragement of my devoted teacher

and assurance, that I have been able to complete the partial

fulfillment of the required course of B.C.A. this was not possible

without their buoyant support and assurance.

     My special thanks to Mrs. Mandeep Kaur (Practical Guide) for

allowing me to fully utilize the resource available in college and to

give me possible help & their co-operation and explaining fine points

my Practical and patiently listening my problems and helping me

whenever needed during my Practical.

     Though due to care has been taken in the preparation and

printing, I regret for any inconvenience that may be caused to

readers an account of any printing mistake.
     This is to certify that the Practical entitled “UNIX Practical
Report” is being made by the student of Maharaja Ranjit Singh
Khalsa Technical College, BATHINDA. For the partial fulfillment of the
award of degree of B.C.A. from Maharaja Ranjit Singh Khalsa
Technical College affiliated to PUNJAB TECHNICAL UNIVERSITY (PTU).
This Practical is confided work carried out by the candidate under my
guidance and supervision.

                                                 PRACTICAL GUIDENCE:
                                                       Miss Rupali Grover
The UNIX file system:
                             Before we learn any more UNIX commands it is
essential to understand the UNIX file system since UNIX treats everything it
knows and understands, as a file. All utilities, applications, data in UNIX is
stored as files. Even a directory is treated as a file which contains several other
files. The root directory is denoted as slash (/). Branching from the root there
are several other directories called bin, lib, usr, etc, tmp, dev. The root
directory also contains a file called UNIX which is UNIX karnel itself.
                             If, for example, we invoke sidekick in middle of
some calculation being done, then all work on the calculations would be
stopped as the computer responds to sidekick. Once you are through with
sidekick and you hit a key to go out sidekick the calculations would then be
resumed. Using the timer interrupted it schedules the CPU time between
programs. These time periods are known as time-slices. If there were 10
programs running at one time, the microprocessor would keep switching
between 10 programs.
                               Does UNIX give equal time-slices to all programs
running in memory? No. There may be some programs that are relatively more
important. For example, those that wait for user responses are given a higher
priority. Programs which have the same priority are schedule on a round-robin

                          UNIX has excellent provision for communicating with
fellow user. The communication may be within the network of a single main
computer, or between two or more such computer networks. The user can
easily exchange mail, data, and programs through such networks. You may be
two feet away or at two thousand miles your mail will hardly take any time to
reach its destination.

                         UNIX allows sharing of data, but not indiscriminately.
Had it been so, it would be the delight of mischief-mongers and useless for any
worthwhile enterprise. UNIX has three inherent provisions for protecting data.
The first is provided by assigning passwords and login names to individual users
ensuring that not anybody can come and have access to your work.
                          Lastly, there is file encryption. This utility encodes
your file into an unreadable format, so that even if someone succeed in
opening it. Your secret is safe. Of course should you want to see the contents,
you can always decrypt the file.

                         One of the main reasons for the universal popularity
of UNIX is that it can be ported to almost any computer system, with only the
bare minimum of adaptations to suit the given computer architecture. As of
today, there are innumerable computer manufactures around the globe, and
tens of hundreds of hardware configurations.
                       (a) It has a hierarchical file structure.
                       (b) Files can grow dynamically.
                       (c) Files have access permissions.
                       (d) All devices are implemented as files.
  These features would be discussed in detail in the following pages.

        Creating Files:
                         Now that we understand how the file system is
organized in UNIX let us learn a few elementary file related commands. There
are two commands to do so: touch and cat. And this is how they are to be
        $ touch sample
                         This creates a file called 'sample'. However, the size of
the file would be zero bytes since touch doesn’t allow you to store anything in
a file. Then dose touch serves any purpose? Yes, when we want to create
several empty files quickly. This can be done by saying.

        $ touch sample1 sample2 sample3 sample4 sample5
                          You would agree that this is a refreshingly simple way
of creating the empty files. But if we want to store new lines in a file? Just type
the command,

        $ cat > test
                         Now press the enter key and you would find the cursor
positioned in the next line, waiting for you to type the matter that you want to
store in the file 'test'. Type in two lines of text:

        Valderama, Valderama pass the ball to Asprilla
        Asprilla, Asprilla shoot the ball into the nat
                            Once you are through with this press the keys Ctrl d.
In UNIX the keys Ctrl d indicate the EOF or end of file character. To display the
contents of a file under DOS, we use the type command. In UNIX, its
counterpart is cat, derived from concatenate. Thus, to see the contents of the
file test that we created above we should say,

         $ cat test
                           Now we know two uses of the cat command. One is to
create new files and another to display the contents of an existing file. cat has
a few more aces up its sleeve. It can concatenate the contents of two files and
store them in the third file.

         $ cat sample1 sample2 > newsample
                            This would create newsample which contains of
sample1 followed by that of sample2. A word of caution. If newsample already
contains something it would be overwritten. If you want that it should remain
intact and contents of sample1 and sample2 should get appended to it then
you should use the 'append output redirection operator', >>, as shown below:

         $ cat sample1 sample2 >> newsample

       Including in File Play:
                             Now that we know how to create the files and
display them let us indulge ourselves in more file related commands. Firstly, it
allows aliasing of commands. That is, you can decide what name you want to
call a command by. if you want to save even more on the typing work. This
feature is similar to the provided by the program DOSKEY in MS-DOS

      Listing files and directories:
                             Is is to UNIX as DIR is to DOS. It gives the directory
listing, or lists the contents of the current or specified directory. Let us being
with the plain and simple Is without any options.
       $ Is
                                    No, don't fall for filenames that are
present in the current directory. Let us now create a file and then see
whether we can list it using Is.

          $ cat > .cricket
          Surat is different than Sharjah
          So sixs not co0me so easily at sharjah
        Ctrl d
                    Did you accept an error because our filename
began with a '.'?

         $ Is
                      Where has the file .cricket gone? Well, well. If
we want the list even the hidden files we need to use the -a option of

         $ Is -a

      Directory Related Commands:
                               When the user logs in he is always
brought to his default working directory. A convenient way of finding
in which directory you are a pwd command is provided.

         $ pwd
                                Hence the path from the root directory is
listed as usr/usr1. Note that unlike DOS where \ is used to specify a
path, in UNIX a / is used.

                                Another commanly used directory command is
mkdir. So while mkdir is fine, MKDIR simply won't touch the right chords.

        $ mkdir book
                                The above command creates directory named
book.It create all the parent directories specified in the given path too.Here's
an example.
         $ mkdir -p works/bpb/UNIX/book

                                 Dedicated to removing directories is the
command rmdir, though rm is also capable to the job. With the -p option,
rmdir wields enough power to remove not only the specified directory,
However rmdir only removes empty directories.
                     Thus, to remove the directory book created earlier, we say

         $ rmdir works/bpb/UNIX/book

               In order to remove parent directories of book, we say

         $ rmdir -p works/bpb/UNIX/book

                           In UNIX parlance too, cd is for changing over to new

         $ mkdir newdir
             $ cd newdir

                                 cd when given without any argument is
interpreted by the shell as a request to change over to current user's home
directory. Stray where you please, a cd will bring you back where you belong -
to your home directory.

           $ cd
           $ pwd

Disk Related Commands:
                                 One of the major concerns of the system
Administrator of a UNIX installation is efficient hard disk management. Since
the UNIX file system is installed usually on a hard disk its upkeep is of primary
importance. The System Administrator has to regularly monitor the integrity of
the file system and amount of the disk space available. Neglecting this may
eventually lead to a system crash. Let's see what are the commands usually
used for the upkeep of hard disk.

Links with DOS:
                                 Many users move to the multiuser OS like UNIX
after having spent a lot of time with a single user OS like MS-DOS. The
commands for carryng out these oprations are fairly straight-forward. Some of
these commands are exemplified below
                          If you want to read some DOS formatted floppy, you
simply have to say:

        $ dosdir a:
                           In order to see the contents of a DOS file, we can use
        $ doscat a:filename

                                 Similarly, dosmkdir, dosrmdir, dosrm and dosls
also function on DOS formatted disks as their counterparts, mkdir, rmdir, rm
and Is work in UNIX environment. Not only this, we can also format a floppy so
that DOS understands it using the command dosformat.
                                 Though all these utilities are usefull, the most
important utility in this area is doscp, since it is the one which would help you
move files from DOS to UNIX and vice versa. For example,

        $ doscp trail a:
                           Will copy the file trail from current UNIX directory to
the DOS formatted floppy in A drive.

File Related Commands:
                                 UNIX envisages a host of possible ways in
which we might want to operate on files, and hence provides a sizeable
number of commands that help us manipulate files. For now let us take a look
at some of the more commonly used commands with their numerous options.

                                 A simple and useful command, it counts the
number of lines, words and characters in specified files. It comes with the
option -I, -w and c which allow the user to obtain the number of lines, words or
characters individually or in any desired combination.
         $ wc -ic file1 file2
         file1 20 571
         file2 30 804

                                 As the name suggests the sort command can
be used for sorting the content of a file. The simplest form of sort command
would be:

        $ sort myfile

                                 Like sort, cut is also a filter. True to its name, it
cuts or picks up a given number of character or fields from the specified file. If
the name happens to be the second field and the division the seventh you
would say

          $ cut -f 2,7 empinfo
                                 If we are to view fields to through 7 we can say,

          $ cut -f 2-7 empinfo
                                 As a result, the first 15 columns from each line
in the file empinfo would be displayed.

                                  grep is an acronym for 'globally search a
regular expression and print it'. Some metcharacters like ''. '?', '[]' and '!' we
learnt in chapter 2. Knowing the versatility of the metacharacters, what
powers they yield to grep can easily be imagined. Let us begin with the
simplest example of usage of grep.

            $ grep picture newsfile

                                  The unintuitive dd is a disguise for an
extremely versatile command for file manipulation. dd converts and copies a
file, allowing plenty of choices. For example,

            $ dd if=report of=document conv=ebcdic, ucase
                                  Following is the list of other options available
with dd.

      Option               Meaning
      count=n              Copy only n input records
      conv=ascii           Convert ebcdic to ascii
      conv=Icase           Convert alphabets to lower case
conv=noerror     Continue processing if error encountered
conc=...,...     Several comma separated conversions
skip=n           Skip n input records before starting copy


To top