You are on page 1of 26

Gyan Ganga College of Technology, Jabalpur

Department of Computer Science & Engineering

Lab Manual

CS505 LINUX LAB

Student Name……………………………..

Enrollment No…………………………….

Faculty Incharge
Kamaljeet Singh kalsi
CSE, GGCT

Session: 2021-22
INDEX
S.NO NAME OF PRACTICAL DATE PAGE NO. REMARKS

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.
Practical No-1

AIM- To Study basic & User status Unix/Linux Commands.

Theory- Linux Commands


Commands tell the operating system to perform set of operations.
The various commands are as follows-
Command: man
The man command - the manual command - is used to show the manual of
the inputted command. example:

$man cd
Command: history
History command shows all the commands that you have used in the past for the
current terminal session. This can help you refer to the old commands you have
entered and re-used them in your operations again.
$history
Command: clear
to clear the screen.
$clear

Command: date
to see the system’s date.
$date

Command: time
to see the system’s time.
$time

Command: cal
It is used to see the calendar of any specific month, or a complete year.
$cal 11 2018
will show the calendar of Nov 2018.

Command: who
It is used to see the details of various users who are currently log in.
$who

Command: ps
It is used to see various process running at a terminal.
$ps

Command: pwd
It is used to see the present working directory.
$pwd
Practical No-2

AIM- Study & use of commands for performing arithmetic operations with Unix/Linux.

Theory- The Bourne shell didn't originally have any mechanism to perform simple arithmetic but it uses
external programs, either awk or the must simpler program expr.
Here is simple example to add two numbers −
#!/bin/sh
val=`expr 2 + 2`
echo "Total value : $val"
This would produce following result −
Total value : 4
There are following points to note down −
There must be spaces between operators and expressions for example 2+2 is not correct, where as it
should be written as 2 + 2.
Complete expression should be enclosed between ``, called inverted commas.
There are following arithmetic operators which we are going to discuss –
There are following arithmetic operators supported by Bourne Shell.
Assume variable a holds 10 and variable b holds 20 then −
Show Examples
Operator Description Example

+ Addition - Adds values on either side of the `expr $a + $b` will give 30
operator

- Subtraction - Subtracts right hand operand from `expr $a - $b` will give -10
left hand operand

* Multiplication - Multiplies values on either side `expr $a \* $b` will give 200
of the operator

/ Division - Divides left hand operand by right `expr $b / $a` will give 2
hand operand

% Modulus - Divides left hand operand by right `expr $b % $a` will give 0
hand operand and returns remainder

= Assignment - Assign right operand in left a=$b would assign value of b into a
operand

== Equality - Compares two numbers, if both are [ $a == $b ] would return false.


same then returns true.

!= Not Equality - Compares two numbers, if both [ $a != $b ] would return true.


are different then returns true.
Practical No-3

AIM- Create a file called wlcc.txt with some lines and display how many lines, words and characters are
present in that file.

THEORY : Word count command -


Command: wc
$ wc[options] filename.
Gives the number of lines, words and characters in a file called filename
$wc –l filename
Gives the number of lines
$wc –w filename
Gives the number of words
$wc –c filename
Gives the number of characters

PROCEDURE : We will perform the practical in following steps :

STEP : 1). Create the file wlcc.txt using vi-editor :


vi wlcc.txt
Insert text using esc + i
Welcome to the world of Linux
Then save and quit after writing the text using esc + : + wq

STEP : 2). Go to the shell prompt and type command wc to view the number of
Lines, Words and Characters.
Practical No-4

AIM- Append ten more simple lines to the wlcc.txt file created above and split the appended file into 3
parts. What will be the names of these split files? Display the contents of each of these files. How many
lines will be there on the last file?

Theory- echo "line 1" >> greetings.txt


echo "line 2" >> greetings.txt
echo "line 3" >> greetings.txt
echo "line 4" >> greetings.txt
echo "line 5" >> greetings.txt
echo "line 6" >> greetings.txt
echo "line 7" >> greetings.txt
echo "line 8" >> greetings.txt
echo "line 9" >> greetings.txt
echo "line 10" >> greetings.txt

SYNTAX- split [OPTION]... [INPUT [PREFIX]]


split -1 2 example.txt
Practical No-5

AIM- Given two files each of which contains names of students. Create a program to display only those names that are
found on both the files.
Theory-

$ comm /path/to/file1/ /path/to/file2

$ comm -1 /path/to/file1/ /path/to/file2

$ comm -2 /path/to/file1/ /path/to/file2

$ comm -2 /path/to/file1/ /path/to/file2

Where-


-1 : suppress lines unique to FILE1

-2 : suppress lines unique to FILE2

-3 : suppress lines that appear in both files
Practical No-6

AIM- Create a program to find out the inode number of any desired file.

Theory- Use the ls command with -i option to view the file inode number. The inode number of the file
will be shown in the first field of the output.
The inode stands for index node or index number is a data structure in a Linux file system that stores
information about a file and directory.
File systems in general have two parts, those are metadata and actual data.
Each file has an inode containing metadata about the file. Each file in a filesystem has a unique inode
number. Inode numbers are guaranteed to be unique only within a filesystem.
You may get the following error when inode is full on the file system. No space left on device or running
out of Inodes.
Inode stores the following information about a file.
 Size of the file.
 Device ID
 User ID (UID)
 Group ID (GID)
Practical No-7

AIM- Study & use of the Command for changing file permissions.

THEORY : File Permissions:


Each file in UNIX/LINUX has an associated permission level. This allows the user to prevent
others from reading/writing/executing their files or directories
Command “ls –l filename ” is used to find permission level of that file. The
permission levels are:
1. “r” means “read only” permission = (4)
2. “w” means “write” permission = (2)
3. “x” means “execute” permission = (1)

Command: change mode (chmod)


If you own a file, you can change its permissions with “chmod”.
Syntax:
$ chmod [user/group/others/all]+[permission] filename

Or $ chmod 755 filename

User Group Other

Procedure :

1. Go to any terminal ( or $ prompt ) and type command ls –l


2. After the list of files and directories is displayed along with mode of permission
, now select any file.
3. Change the mode of permission of the selected file using following command :
$chmod 755 filename
4. Again type ls –l command and now the permission of the desired file is
changed.

In the diagram below, we see how the first portion of the listing is interpreted. It consists of a
character indicating the file type, followed by three sets of three characters that convey the
reading, writing and execution permission for the owner, group, and everybody else.
chmod

The chmod command is used to change the permissions of a file or directory. To use it, you
specify the desired permission settings and the file or files that you wish to modify. There are
two ways to specify the permissions. In this lesson we will focus on one of these, called the octal
notation method.

It is easy to think of the permission settings as a series of bits (which is how the computer thinks
about them). Here's how it works:

rwx rwx rwx = 111 111 111


rw- rw- rw- = 110 110 110
rwx--------= 111 000 000

and so on...

rwx = 111 in binary = 7


rw- = 110 in binary = 6
r-x = 101 in binary = 5
r- -= 100 in binary = 4

Value Meaning

(rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
777
(rwxr-xr-x) The file's owner may read, write, and execute the file. All others may
755 read and execute the file. This setting is common for programs that are used by all
users.

(rwx------) The file's owner may read, write, and execute the file. Nobody else has
700 any rights. This setting is useful for programs that only the owner may use and
must be kept private from others.

666 (rw-rw-rw-) All users may read and write the file.

(rw-r--r--) The owner may read and write a file, while all others may only read
644 the file. A common setting for data files that everybody may read, but only the
owner may change.

(rw------) The owner may read and write a file. All others have no rights. A
600
common setting for data files that the owner wants to keep private.

Directory Permissions

The chmod command can also be used to control the access permissions for
directories. Again, we can use the octal notation to set permissions, but the
meaning of the r, w, and x attributes is different:

 r - Allows the contents of the directory to be listed if the x attribute is


also set.
 w - Allows files within the directory to be created, deleted, or renamed if
the x attribute is also set.
 x - Allows a directory to be entered (i.e. cd dir).
Practical No-8

AIM- Write a pipeline of commands, which displays on the monitor as well as saves the information about the
number of users using the system at present on a file called usere.ux.

Theory- The novel idea of Pipes was introduced by M.D Mcllory in June 1972– version 2, 10 UNIX installations.
Piping is used to give the output of one command (written on LHS) as input to another command
(written on RHS). Commands are piped together using vertical bar “ | ” symbol.

Syntax:- command 1|command 2


Example:
Input: ls|more
Output: more command takes input from ls command and appends it to the standard output. It displays as many
files that fit on the screen and highlighted more at the bottom of the screen. To see the next screen hit
enter or space bar to move one line at a time or one screen at a time respectively.
Practical No-9

AIM- Execute shell commands through vi editor.

Theory- vi editor
vi is the most useful standard text editor on your system. (vi is
short for visual editor and is pronounced "vee-eye."). UNIX has a number of editors that can process the
contents of text files, whether those files contain data, source code, or sentences. Editor (VI – editor) is
screen editors which display a part of the file on your terminal screen.

vi. This editor enable you to edit lines in context with other lines in the file.

Now a day you would find an improved version of vi editor which is called vi. Here VIM stands for vi
improved.

The VI is generally considered the de facto standard in UNIX editors because −


It's usually available on all the flavors of UNIX system. Its implementations are very similar across the
board. It requires very few resources.

You can use vi editor to edit an existing file or to create a new file from scratch. You can also use this
editor to just read a text file.

Starting the vi Editor

There are following way you can start using VI editor −

Command Description

Creates a new file if it already does not exist, otherwise opens


vi filename existing

file.

vi -R filename Opens an existing file in read only mode.

view filename Opens an existing file in read only mode.

Following is the example to create a new file testfile if it already does not exist in the current
working directory −

$vi testfile
As a result you would see a screen something like as follows −
~

~
~

"testfile" [New File]

You will notice a tilde on each line following the cursor. A tilde represents an unused line. If a line
does not begin with a tilde and appears to be blank, there is a space, tab, newline, or some other
nonviewable character present.
So now you have opened one file to start with. Before proceeding further let us understanding few minor
but important concepts explained below.

Operation Modes

While working with vi editor you would come across following two modes −

Command mode − This mode enables you to perform administrative tasks such as saving files,
executing commands, moving the cursor, cutting yanking and pasting lines or words, and finding and
replacing. In this mode, whatever you type is interpreted as a command.

Insert mode − This mode enables you to insert text into the file. Everything that's typed in this
mode is interpreted as input and finally it is put in the file .

The vi always starts in command mode. To enter text, you must be in insert mode. To come in insert mode
you simply type i. To get out of insert mode, press the Esc key, which will put you back into command mode.

Hint − If you are not sure which mode you are in, press the Esc key twice, and then you'll be in command
mode. You open a file using vi editor and start type some characters and then come in command mode to
understand the difference.
Getting Out of vi

The command to quit out of vi is :q. Once in command mode, type colon, and 'q', followed by return. If
your file has been modified in any way, the editor will warn you of this, and not let you quit. To ignore this
message, the command to quit out of vi without saving is :q!. This lets you exit vi without saving any of
the changes.

The command to save the contents of the editor is :w. You can combine the above command with the quit
command, or :wq and return.

The easiest way to save your changes and exit out of vi is the ZZ command. When you are in
command mode, type ZZ and it will do the equivalent of :wq.

You can specify a different file name to save to by specifying the name after the :w. For example, if you
wanted to save the file you were working as another filename called filename2, you would type
:w filename2 and return. Try it once.

Moving within a File


To move around within a file without affecting your text, you must be in command mode press Esc twice.
Here are some of the commands you can use to move around one character at a time

Command Description
K Moves the cursor up one line.

J Moves the cursor down one line.

H Moves the cursor to the left one character position.

L Moves the cursor to the right one character

position.

There are following two important points to be noted −

The vi is case-sensitive, so you need to pay special attention to capitalization when using commands.

Most commands in vi can be prefaced by the number of times you want the action to occur. For
example, 2j moves cursor two lines down the cursor location.
There are many other ways to move within a file in vi. Remember that you must be in command mode
pressEsctwice. Here are some more commands you can use to move around the file −

Command Description

0 or | Positions cursor at beginning of line.

$ Positions cursor at end of line.

W Positions cursor to the next word.

B Positions cursor to previous word.

Positions cursor to beginning of current


( sentence.

) Positions cursor to beginning of next sentence.

E Move to the end of Blank delimited word

{ Move a paragraph back

} Move a paragraph forward

[[ Move a section back

]] Move a section forward

n| Moves to the column n in the current line

1G Move to the first line of the file

G Move to the last line of the file

nG Move to nth line of the file

:n Move to nth line of the file

Fc Move forward to c

Fc Move back to c

H Move to top of screen

nH Moves to nth line from the top of the screen


M Move to middle of screen

L Move to bottom of screen

nL Moves to nth line from the bottom of the screen

Colon followed by a number would position the


:x cursor on line number

represented by x

Editing Files
To edit the file, you need to be in the insert mode. There are many ways to enter insert mode from the
command mode –

Command Description

I Inserts text before current cursor location.

I Inserts text at beginning of current line.

A Inserts text after current cursor location.

A Inserts text at end of current line.

O Creates a new line for text entry below cursor location.

O Creates a new line for text entry above cursor

location.

Deleting Characters
Here is the list of important commands which can be used to delete characters and
lines in an opened file.

Command Description

X Deletes the character under the cursor location.

X Deletes the character before the cursor location.


Deletes from the current cursor location to the next
Dw word.

Deletes from current cursor position to the


d^ beginning of the

line.

Deletes from current cursor position to the end of the


d$ line.

Deletes from the cursor position to the end of the


D current line.

Dd Deletes the line the cursor is on.

Copy and Past Commands


You can copy lines or words from one place and then you can past them at another place using following
commands −

Command Description

Yy Copies the current line.

Yw Copies the current word from the character the lowercase w cursor is

on until the end of the word.

P Puts the copied text after the cursor.

P Puts the yanked text before the cursor.


Practical No-10

AIM- Installation, Configuration & Customizations of Unix/Linux.

Theory-
1. Download the Linux distribution of your choice. If you're new to Linux, consider trying a lightweight and
easy to use distribution, such as Ubuntu or Linux Mint. Linux distributions (known as "distros") are typically
available for free to download in ISO format. You can find the ISO for the distribution of your choice at the
distribution’s website. This format needs to be burned to a CD or USB stick before you can use it to install
Linux. This will create a Live CD or Live USB.
 A Live CD or Live USB is a disk that you can boot into, and often contains a preview version
of the operating system that can be run directly from the CD or USB stick.
 Install an image burning program, or use your system’s built-in burning tool if you are using
Windows 7, 8, or Mac OS X. Pen Drive Linux and UNetBootin are two popular tools for
burning ISO files to USB sticks.

2. Boot into the Live CD or Live USB. Most computers are set to boot into the hard drive first, which means you
will need to change some settings to boot from your newly-burned CD or USB. Start by rebooting the computer.
 Once the computer reboots, press the key used to enter the boot menu. The key for your system
will be displayed on the same screen as the manufacturer’s logo. Typical keys include F12, F2,
or Del.
 For Windows 8 users, hold the Shift key and click restart. This will load the Advanced Startup
Options, where you can boot from CD.
 For Windows 10 users, go to advanced boot in settings and click "Restart Now."
 If your computer doesn't give you direct access to the boot menu from the manufacturer's
splash screen, it's most likely hidden in the BIOS menu. You can access the BIOS menu in the
same way that you would get to the boot menu. At the manufacturer splash screen, the key
should be listed in one of the bottom corners.
 Once you're in the boot menu, select your live CD or USB. Once you’ve changed the settings,
save and exit the BIOS setup or boot menu. Your computer will continue with the boot process.
Practical No-11

AIM- Write a shell script that accepts any number of arguments and prints them in the reverse order.

Shell Script-
a=$#

echo "Number of arguments are" $a

x=$*

c=$a

res=''

while [ 1 -le $c ]

do

c=`expr $c - 1`

shift $c

res=$res' '$1

set $x

done

echo Argument in reverse order $res


Practical No-12

AIM- Write a shell script to find the smallest of three numbers that are read from the keyboard.

Shell Script-
echo "enter a: "
read a
echo "enter b : "
read b
echo "enter c : "
read c
s=$a
if [ $b -lt $s ]
then
s=$b
fi
if [ $c -lt $s ]
then
s=$c
fi
echo Smallest of $a $b $c is $s

OUTPUT-
Practical No-13

AIM- Write a shell script that reports the logging in of a specified user within one minute after he/she
logs in. The script automatically terminates if the specified user does not login during a specified period
of time.
Shell Script-
a=`date +%M`
b=`expr $a + 1`
while [ $b -gt `date +%M` ]
do
who | grep $1
if [ $? -eq 0 ]
then
echo "$1 has logged in 1 minute"
exit
fi
done
echo "$1 has not looged in within 1 minute"
Practical No-14

AIM- Installation of SAMBA, APACHE, TOMCAT.

Theory- Installing Samba


1. On your Linux machine, open a terminal window.
2. Install the necessary software with the command sudo apt-get install -y samba samba-common python-glade2 system-config-
samba.
3. Type your sudo password and hit Enter.
4. Allow the installation to complete

You can install Apache anywhere, such as a portable USB drive (useful for client demonstrations).

1. Step 1: Configure IIS. ...


2. Step 2: Download the files. ...
3. Step 3: Extract the Files. ...
4. Step 4: Configure Apache. ...
5. Step 4: Change the Web Page Root (optional) ...
6. Step 5: Test your Installation. ...
7. Step 6: install Apache as a Windows service.

Installing Apache Tomcat on Windows

1. In the left-hand Download menu, click the latest available Tomcat version.
2. Locate the Binary Distributions area and in the Core list click on the ZIP file corresponding to the required Windows version.
3. Save the ZIP file in a temporary directory.
4. Unpack the downloaded ZIP file into the target folder on the computer.
Practical No-15

AIM- Implementation of DNS, LDAP services.

Theory-
Implementation of DNS: DNS is a host name to IP address translation service. DNS is a distributed database implemented
in a hierarchy of name servers. It is an application layer protocol for message exchange between clients and servers.
Requirement
Every host is identified by the IP address but remembering numbers is very difficult for the people and also the IP addresses are not static
therefore a mapping is required to change the domain name to IP address. So DNS is used to convert the domain name of the websites to their
numerical IP address.
Domain :
There are various kinds of DOMAIN :
1. Generic domain : .com(commercial) .edu(educational) .mil(military) .org(non profit organization) .net(similar to commercial) all these are
generic domain.
2. Country domain .in (india) .us .uk
3. Inverse domain if we want to know what is the domain name of the website. Ip to domain name mapping.So DNS can provide both the
mapping for example to find the ip addresses of geeksforgeeks.org then we have to type nslookup
It is Very difficult to find out the ip address associated to a website because there are millions of websites and with all those websites we
should be able to generate the ip address immediately.

LDAP Services:
Linux provides both server-side and client-side support for the Lightweight Directory Access Protocol (LDAP) facility. This is a standards-based
facility, so it is compatible with other LDAP implementations, including Microsoft’s Active Directory. Data suitable for a directory service has
low volatility as LDAP is optimized for read-mostly access; database systems are tailored for more volatile data. A classic example of data
suitable for directory services is the ordinary telephone directory.

LDAP content is organized according to a data definition language, or schema. Standard schema are available but customized schema are also
possible. Much of the value of using LDAP is to consolidate corporate information about resources, such as login passwords, to centralize
administration efforts.

The Linux LDAP implementation has two main components: slapd, a stand-alone LDAP daemon, and slurpd, a stand-
alone LDAP replication daemon. The two daemons work cooperatively, slapd maintaining the local LDAP information and slurpd
replicating these changes to additional LDAP directories.
Practical No-16

AIM- Study & installation of Firewall & Proxy server

Theory-

Installation of Firewall:-

Setting Up a Firewall:

1. Set up system and security settings. From the Start menu, click Control Panel, then click System and Security. ...
2. Select program features. Click Turn Windows Firewall on or off from the left side menu. ...
3. Choose firewall settings for different network location types.

Installation of Proxy server:


Here's how to set a proxy manually in Windows 10:

1. Open Settings.
2. Click Network & Internet. ...
3. Click Proxy. ...
4. In the Manual Proxy Setup section, set the Use a Proxy Server switch to On.
5. In the Address field, type the IP address.
6. In the Port field, type the port.
7. Click Save; then close the Settings window.

You might also like