You are on page 1of 5

Operating Systems Lab Oct 2018

Hand-out 2: Lab 02 Instructions Instructor: Shahid Abid

Lab 2: Introduction to Linux

Objectives
 Introduce the Linux environment and basic shell commands.

 Write, compile, and execute a “Hello World!” C program in Linux environment


using gcc.

2. Introduction
 Fedora is available to you as virtual machine. Fedora is an open-source
Linux-based operating system alternative to Windows. We will learn the
basic desktop environment and common shell commands. Please login
using the credentials provided by the instructor.

 Play with the fedora desktop environment.



3. Linux Basics

Linux System
Linux System can be split into two parts:
 CLI (Shell)
 GUI (X-Windows Server with Gnome, KDE etc. window manager)
We will work in Kernel / User modes using root / test users.
Formally, a Shell is interface between a user and a Linux operating system,
i.e. user interacts with the Linux operating system through the shell.

Kernel is the core of Linux Operating System, which is operational as long as


the computer system is running. The kernel is part of the Linux Operating system
which consists of routines which interact with underlying hardware, and routines
which include system calls handling, process management, scheduling, signals,
the file system, and I/O to storage devices.

Linux File System Hierarchy


Unlike DOS, which permits you to organize your folders (directories) and files anyway you
please, the Linux file system is organized into a standard directory structure. A portion of
the Linux directory structure is pictured below:

1/5
/home Users’ home directory

/etc All system administrator commands, configuration files, and


installation control files.

/bin The core set of system commands and programs. Most systems
cannot boot (initially start) without executing some of the
commands in this directory.

/dev The device files used to access system peripherals (for


example, your terminal can be accessed from /dev/tty).

/lib The standard set of programming libraries required by Linux


programs.

/tmp Temporary files created and used by many Linux programs.


/var Log files, spool files etc.

/root The root user’s home directory.

/usr/bin Common commands and programs.

/usr/doc Documentation

/usr/games Games

/usr/include Header files

/usr/info Online documentation

/usr/man Manual pages (help)

/usr/share Shared information

2/5
3. Basic Commands
In this section, we learn some basic Linux commands e.g., ls, cd, mkdir etc.

Directory Commands
Command Description
ls List the file in the directory, just like dir command in DOS.

Options

-a Display all the files, and subdirectories,


including hidden files.
-l Display detailed information about each file,
and directory.
-r Display files in the reverse order.

Command Description
mkdir directory-name Creates a new directory.
Directory-name specifies the name of the new
directory. If the name doesn’t begin with a
slash, the new directory is created as a
subdirectory of the current working directory. If
the name begins with a slash, the name defines
the path from the root directory to the new
directory.

$cd /
Try to use the following command first because this
will bring you back to your home directory
$ cd

mkdir books

This command will create a new directory under the home directory.

3/5
How would you go to the directory books?
Command Description

cd Change to another directory.

For Example:
$cd dir-name
To change to any sub-directory under the current directory.

$cd books
(When Enter is pressed, the prompt becomes)

/books$
Do you see any difference between the two prompts?
Now you are in books directory, a step down to home. How could you go up?

$ cd .. (there’s space between cd and ..) Now you will again be in your parent directory.
And the prompt becomes: $

4. C Program in Linux Environment


In this section we write, compile, and execute a Hello Word program in Linux
environment.
Step 1: Create a director; mkdir lab1
Step 2: Switch to director; cd lab1
Step 3: Create a file; touch Hello.c
Step 4: Open the file; gedit Hello.c
Step 5: Type the following source code:
#include<stdio.h>
main()
{
printf("Hello World");
}

Step 6: Compile; gcc –o Outputhello Hello.c


step 7: Execute; ./Outputhello

4/5
Shahid Abid (shahidabid@gmail.com)

5. In-Lab Exercises
1. Suppose you need to list the contents of a directory in long listing format. What
parameters should you use with ls to perform this task? Hint: remember that the
man command gives you an online reference manual for any Linux command.

2. Create the following directory structure:

3. Write a program that odd numbers from 1 to 10 and print their sum, Compile and run
it using gcc.

4. Learn the usage of find command. Hint: remember that the man command
gives you an on line reference manual for any Linux command and also you
can get help from the Internet.
Important note: Don't copy paste exact information .write in your own word after
understanding.

Important: The lab instructor will grade you at the end of the lab.

Submission: A word document containing:

 Front Page that includes your Name, Lab no and Roll no. at least.

 Screen Shot for each question (Note: If there is need of more screen shots in any
task then add all of them in your document).

********** GOOD LUCK **********

Shahid Abid/Lab#1 5/5

You might also like