Birla Institute of Technology & Science, Pilani First Semester 2015-2016, Computer Programming (CS F111) Lab #1
Birla Institute of Technology & Science, Pilani First Semester 2015-2016, Computer Programming (CS F111) Lab #1
Birla Institute of Technology & Science, Pilani First Semester 2015-2016, Computer Programming (CS F111) Lab #1
Summary
INTRODUCTION
Figure 1
Exercise 1.1 (Trivial): Spot the corresponding physical parts in the computer in front of
you. [Some parts such as the speaker may be missing.]
The PC tower is just a collection of various components connected together and
ergonomically packaged into a box. The internals of a typical PC tower are shown in
Figure2.
Figure2
Operating System
The operating system is software that manages the hardware and helps you to interact with
the computer. There are several Operating Systems available on the market today for PCs.
Some of the most popular ones are:
Windows (Windows XP, Windows Vista, and Windows 7) produced by Microsoft.
Unix/Linux (AIX produced by IBM, Fedora produced by RedHat, HP-UX produced
by HP etc.)
3. Mac OS (produced by Apple).
We will be using UNIX/LINUX for our lab work.
1.
2.
What is UNIX?
UNIX is an operating system originally developed at AT&T Bell Laboratories. It became very
popular among the scientific, engineering, and academic communities due to its multi-user
and multi-tasking environment, flexibility and portability, electronic mail and networking
capabilities, as well as the numerous programming, text processing and scientific utilities
available [If you do not understand few words here, don't worry].
Unix does not refer to a single operating system but to a family of operating system i.e.
there are many flavors (aka. variants, types, or implementations) of Unix available. Linux is
a modern day variant developed originally by Linus Torvalds and several implementations
of Linux are supported today by the open source community. Although based on a core set
of Unix commands, different flavors have their own unique commands and features, and
are designed to work with different types of hardware.
The following is some of the well-known Unix flavors,
1.Ubuntu (Linux variant)
2.Fedora (Linux variant)
3. Debian (Linux variant)
4. Free BSD (One of the old Unix variants still available)
Figure 5.
Go to Application on top of the Desktop and click on System Tools. Then click on
Terminal. You will see a window as in Figure6, on which you will learn /practice /
program throughout this course by typing text commands.
Figure 6
You would like to find out what is inside your home directory.
List the contents of the current directory (Command Name: ls)
Do you see the following prompt?
[user@localhost:~] $
..
.bash_history
.bash_profile
.bashrc
.kde .lesshst
Observe the result of our previous command ls a : all the files listed as result start with a DOT (.)
These files are hidden files. (Do not fiddle with these files now!!!). Also observe the first two results.
A Single dot (.) in UNIX means the current directory and two consecutive dots (..) means the parent
of the current directory.
[Note: There is a space between the command name ls and the option a. Most commands in UNIX
have options and optional arguments. Each option is usually preceded by a space and then a hyphen
(-) End of Note]
Type the following commands, and observe the outcomes.
[user@localhost:~] $ ls .
[user@localhost:~] $ ls ..
EXERCISE-1
1. Try the following commands now (and try to understand the results too)
ls
ls ~
ls ~/exercises
ls ./..
ls ~/..
2. Create two subdirectories test1 and test2 under exercises
Observe the two prompts above.
Before you enter the command you can see a ~ symbol towards the end of the prompt
Once you entered the command you can find the ~ symbol is replaced by exercises.
exercises is the present working directory. Then what does the ~ symbol mean?
EXERCISE-2
Consider you are in your home directory. Change to the exercises directory.
[user@localhost:~] $ cd exercises
Now create a new directory exercise1 in exercises directory
[user@localhost:~/exercises] $ mkdir exercise1
Create a directory inside exercise1 with a name exercise2
[user@localhost:~/ exercises] $ mkdir exercise1/exercise2
Go to exercise2
[user@localhost:~/ exercises] $ cd exercise1/exercise2
Create a directory inside exercise2 with a name test
[user@localhost:~/exercises/exercise1/exercise2] $ mkdir test
Try to execute the following commands and observe the results
(a)[user@localhost:~/exercises/exercise1/exercise2] $ ls .
(b)[user@localhost:~/exercises/exercise1/exercise2] $ ls ./..
(c)[user@localhost:~/exercises/exercise1/exercise2] $ ls ./../..
Recall that '.' indicates present working directory and '..' indicates the parent of present directory.
LONG LISTING OF A DIRECTORY
1. In this section you will learn various options which can be used with ls command to provide
various file related information.
a) ls command when used with a option lists all the files in your directory including those that
start with a dot(.), such files are hidden files. Execute the following command
[user@localhost:~/ Lab2]$ ls a
(Please give a space between ls, and a), observe the output
b) ls command when used with l option displays Unix file types, permissions, number of hard
links, owner, group, size, date, and filename. Execute the following command
[user@localhost:~/ Lab2]$ ls l
(Please give a space between ls, and l), observe the output
GENERAL PURPOSE UNIX COMMANDS
1. The clear command- Used to clear the screen.
2. The date command displays todays date. Execute the following command and observe
the result. You will see todays date.
[user@localhost:~/ Lab2]$ date
3. The who command displays all the users who are currently logged in your system
(online). Execute the following command and observe the result.
[user@localhost:~/ Lab2]$ who
4. The who am i command displays your own identity. Execute the following command and
you will be able to see output as your own user identity.
[user@localhost:~/ Lab2]$ who am i
5. The cal command It is a standard program on UNIX and UNIX-like operating systems
that prints an ASCII calendar of the given month or year. Execute the following commands
and see the output.
a. [user@localhost:~/ Lab2]$ cal 2010 (give space between cal, 2010)
b. [user@localhost:~/ Lab2]$ cal 2 2010 (give space between cal, 2, and 2010)
6. The man command- provides reference information on topics, such as commands,
subroutines, and files. The man command provides one-line descriptions of commands
specified by name. The man command also provides information on all commands whose
descriptions contain a set of user-specified keywords. This is the command which you will
be using to get any information about inbuilt functions while writing C programs.
Example: Type the following
[user@localhost:~]$man ls
You will see the following
Which tells you details how to use ls command. Letter or string starting with '-' are optional
with ls command.
Use Ctrl z to come out of manual page.
So what you understand here is, the structure of UNIX command is
<command name><space><option1><space><option2>.
So, play with man command to understand UNIX commands in detail. Try out the options you can
use with the commands you have already learnt. What happens when you type man man ?