CS 505 - Linux Laboratory Manual - Final - 1659164997
CS 505 - Linux Laboratory Manual - Final - 1659164997
LABORATORY MANUAL
LINUX LABORATORY
CS 505
V SEM (CSE)
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
CERTIFICATE
This is to certify that Mr./Ms…………………………………………………………………………..………… with RGTU Enrollment
No. 0832 ..…………………………..has satisfactorily completed the course of experiments in Linux laboratory, as
prescribed by Rajiv Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal for V Semester of the Computer Science &
Signature of
Faculty In-Charge
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
INDEX
Date of Signature of
Expt. No. List of Experiments Conduction Faculty in-
Charge
1 To study the basic as well as user status UNIX/Linux commands
Study and use of commands for performing arithmetic operations
2
with Unix/Linux
Create a file called wlcc.txt with some lines and display how many
3
lines, words and characters are present in that file
Append ten more simple lines to the wlcc.txt file, split the
4 appended file into 3 parts and display the contents of each of
these files
Write a program to display only those names that are found in the
5
given two files, each of which contains name of students
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 1 To study the basic as well as user status UNIX/Linux commands
Viva Questions:
1. Describe functions of the Linux Operating System.
2. What is the use of the “pwd” command?
3. Describe file and directory in Linux.
4. Explain different variations of "ls" command.
5. Explain the use of the "cat" command.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 2 Study and use of commands for performing arithmetic operations with Unix/Linux
/ (Division) Divides left hand operand by right hand operand `expr $b / $a`
It is very important to understand that all the conditional expressions should be inside square braces with
spaces around them, for example [ $a == $b ] is correct syntax whereas, [$a==$b] is incorrect syntax.
All the arithmetical calculations are performed using long integers.
Example:
Here is an example that uses all the arithmetic operators –
Procedure:
Step 1: Start with the header file.
Step 2: Initializes the two variables.
Step 3: Perform arithmetic operations and store the resultant value in the third variable.
Step 4: Print the value of third variable.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Viva Questions:
1. Describe the BASH.
2. Explain the functions of Linux Kernel.
3. Explain assignment and equality operator.
4. Explain modulus and division operator.
5. Describe the basic working of an assignment operator.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 3 Create a file called wlcc.txt with some lines and display how many lines, words and characters
are present in that file
Viva Questions:
1. Explain the procedure to display the number of characters of the text file.
2. Explain the working of “wc” command.
3. Describe the various options available with “wc” command.
4. Describe the process to read a text file.
5. Explain the importance of “Vi” Editor.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 4 Append ten more simple lines to the wlcc.txt file, split the appended file into 3 parts and
display the contents of each of these files
Viva Questions:
1. Describe the “split” command.
2. Explain the concept of “chunk”.
3. Explain the procedure to append text in a file.
4. Describe “prefix” and “suffix”.
5. Describe “cat” command.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 5 Write a program to display only those names that are found in the given two files, each of
which contains name of students
Theory: In this experiment user will create two files i.e., file1 and file2 which contains the name of the
students. Both the files have to be compared by using Linux command in order to find out the name of the
students which are common in both the files.
Syntax:
$comm [OPTION]... FILE1 FILE2
Using comm: used for comparing the two files, therefore the syntax of “comm” command needs two
filenames as arguments.
Procedure
Column one contains lines unique to FILE1
Column two contains lines unique to FILE2,
Column three contains lines common to both files.
1. suppress column 1 (lines unique to FILE1)
2. suppress column 2 (lines unique to FILE2)
3. suppress column 3 (lines that appear in both files)
check-order: check that the input is correctly sorted, even if all the input lines are pairable
nocheck-order: do not check that the input is correctly sorted
output-delimiter=STR: separate columns with STR
Example: Let us suppose there are two sorted files file1.txt and file2.txt and now user will use the “comm”
command to compare these two files.
Output:
It contains three columns where the first column is separated by zero tab and contains names only present
in file1.txt, the second column contains names only present in file2.txt and separated by one tab and
the third column contains names common to both the files and is separated by two tabs from the beginning
of the line.
Viva Questions:
1. Explain the process to setup directory permissions in Linux.
2. What are the different types of file access permission?
3. Describe the procedure to create user/group in Linux.
4. Describe the various options available with “comm” command.
5. Describe the “grep” command.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 6 Write a command to find the "inode" number of any desired file
Output:
File: 'inode.check'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 806h/2054d Inode: 1179765 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ arunlal) Gid: ( 1000/ arunlal)
Access: 2016-11-15 20:00:07.548968280 +0530
Modify: 2016-11-15 20:00:07.548968280 +0530
Change: 2016-11-15 20:00:07.548968280 +0530
Birth: -
2. ls -il {file-name}
Example:
arunlal@localhost:~$ touch inode.check
arunlal@localhost:~$ ls -i inode.check
output:
1179765 inode.check
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Output:
File: 'inode.check.dir'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 806h/2054d Inode: 1314947 Links: 2
Access: (0775/drwxrwxr-x) Uid: ( 1000/ arunlal) Gid: ( 1000/ arunlal)
Access: 2016-11-15 20:09:21.734325138 +0530
Modify: 2016-11-15 20:09:21.734325138 +0530
Change: 2016-11-15 20:09:21.734325138 +0530
Birth: -
Viva Questions:
1. Describe the "inode" number.
2. Explain the steps to kill the process.
3. What are the various ways to delete a file from the Linux Operating System?
4. What is the role of IO Block?
5. Describe the “stat” command.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 7 To study and use the command for changing file permissions
Aim: To understand the concept of changing the file permissions with the help of command
Theory:
To change directory permissions in Linux the following commands are used -
chmod +rwx : add permissions in the file name
chmod -rwx : remove permission from the directory name
chmod +x : used for the filename to allow executable permissions
chmod -wx : used for the filename to take out write and executable permissions.
Note that “r” denotes read, “w” denotes write, and “x” denotes execute.
To change directory permissions for group owners, use the following commands:
chmod g+w filename
chmod g-wx filename
chmod o+w filename
chmod o-rwx foldername
To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or
“a” (for all).
chmod ugo+rwx foldername :To give access of read, write, and execute permission to everyone
chmod a=r foldername :To give only read permission for everyone
To change permissions in numeric code in Linux, use numbers instead of “r”, “w”, or “x”:
0 = No Permission
1 = Execute
2 = Write
4 = Read
For example:
chmod 777 foldername will give read, write, and execute permissions for everyone.
chmod 700 foldername will give read, write, and execute permissions for the user only.
Viva Questions:
1. Describe the “chmod” command.
2. Explain the various permission numbers of ‘chmod’ command.
3. Describe the procedure to find memory usage.
4. Describe file permissions.
5. Explain the process to find Linux mount points.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 8 To 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 user.ux
Options Description
w -o This option will print blank space for idle times less than one minute.
w user This option will show information about the specified user only.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Options Description
The who command displays the following information for each user currently logged in
to the system if no option is provided -
Login name of the users
who
Terminal line numbers
Login time of the users into the system
Remote host name of the user
who -m -H To display host name and user associated with standard input such as keyboard
who -p -H To show all active processes which are spawned by INIT process
Viva Questions:
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Vi Editing Commands
Table 9.1: Commands of Vi Editor
Command Description
i Insert text at cursor
ESC Terminate insert mode
o Open a new line
r Replace Character
~ Change case of individual character
cw Change word
dd Delete line
Shift+ZZ Save the file and quit
:w Save the file but keep it open
:q Quit without saving
:wq Save the file and quit
Viva Questions:
1. Explain the process to quit from “Vi” editor without saving a file.
2. Describe the procedure to delete the current line from the “Vi” editor file.
3. Explain the features of “Vi” editor.
4. Describe various modes of “Vi” editor.
5. Explain the significance of shell in Linux.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 10 Write a shell script that accepts any number of arguments and prints them in the reverse
order
Procedure:
Step 1: Open the Vi editor and provide a name to the file.
Step 2: Press I to work in insert mode.
Step 3: Initializes the two variables: $d and $rev.
Step 4: Perform the logic to reverse the number (using loop).
Step 5: Store the value in the third variable.
Step 6: Print the value of the third variable.
Viva Questions:
1. Describe shell scripting.
2. What are the different types of shell?
3. Describe the “echo” command.
4. Explain the use of $# command.
5. What is the process to add arguments into the shell script?
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 11 Write a shell script to find the smallest of three numbers that are read from the keyboard
Aim: To acquire the knowledge of taking inputs from the keyboard into the shell script
Theory: Users can store the data with the help of variables. It stores data in the form of characters and
numbers. Similarly, Shell variables are used to store information and it can be used by the shell only.
Example to create a shell variable:
variable ="Hello" // Assign the value Hello to the variable
echo $variable // Print the value of the variable
Procedure:
Step 1: Start with the header file.
Step 2: Initializes the three variables: $a, $b &$c.
Step 3: Perform the logic to evaluate the smallest number among numbers entered by the user.
Step 4: Store the value in the third variable.
Step 5: Print the value of the third variable.
Viva Questions:
1. Explain the procedure to print a greater number among three numbers.
2. Describe the process to print the specific period using shell script.
3. Describe variables in shell scripting.
4. Explain the process to take input from the keyboard.
5. What is the procedure to print the variable value?
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. -12 Write a shell script that reports the logging in of a specified user within one minute after
login
Aim: To acquire the knowledge of a shell script that reports the logging information of a specified user
Theory: In the shell script, various commands are used to provide information about the user.
Procedure:
Step 1: Start with the Vi editor.
Step 2: Retrieve the user name using the who command and login time using the date command.
Step 3: Give the command to print the name and logging details.
Step 4: Print the specific period.
Viva Questions:
1. What is the procedure to get the logging details of a user?
2. Describe the various attributes of “grep” command.
3. What is the use of “users” command?
4. Explain the process to retrieve the login time of the user.
5. Explain the use of “lslogins” command.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
EXPT. No. - 13 To study install, configure and customize Unix/Linux operating system
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Viva Questions:
1. What are the basic elements of Linux?
2. Explain the concept of BASH.
3. Explain the use of ISO file.
4. Explain the functions of the Kernel.
5. What is the use of swap space?
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Viva Questions:
1. Describe the steps to configure the Samba server.
2. What are the advantages of the Samba server?
3. Describe the functions of the Apache Tomcat Server.
4. Explain the use of the port address.
5. Describe the significance of NetBIOS.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Aim: To acquire knowledge about the implementation of DNS and LDAP services
Theory:
DNS stands for Domain Name System.
DNS is a directory service that provides a mapping between the name of a host on the network and its
numerical address.
DNS is required for the functioning of the internet.
Each node in a tree has a domain name, and a full domain name is a sequence of symbols specified by
dots.
DNS is a service that translates the domain name into IP addresses. This allows the users of networks
to utilize user-friendly names when looking for other hosts instead of remembering the IP addresses.
For example, suppose the FTP site at EduSoft had an IP address of 132.147.165.50, most people would
reach this site by specifying ftp.EduSoft.com. Therefore, the domain name is more reliable than the IP
address.
DNS is a TCP/IP protocol used on different platforms. The domain name space is divided into three different
sections.
1) Generic Domains
It defines the registered hosts according to their generic behavior.
Each node in a tree defines the domain name, which is an index to the DNS database.
It uses three-character labels and these labels describe the organization type.
2) Country Domain
The format of the country domain is the same as a generic domain, but it uses two-character country
abbreviations (e.g., us for the United States) in place of three-character organizational abbreviations.
3) Inverse Domain
The inverse domain is used for mapping an address to a name.
When the server has received a request from the client and the server contains the files of only
authorized clients.
To determine whether the client is on the authorized list or not, it sends a query to the DNS server and
asks for mapping an address to the name.
Lightweight Directory Access Protocol (LDAP):
Companies store usernames, passwords, email addresses, printer connections and other static data within
directories.
LDAP is an open, vendor-neutral application protocol for accessing and maintaining that data. LDAP can also
tackle authentication, so users can sign on just once and access many different files on the server.
LDAP is a protocol, so it doesn't specify how directory programs work. Instead, it's a form of language that
allows the users to find the information they need very quickly.
LDAP is vendor-neutral, so it can be used with a variety of different directory programs.
Typically, a directory contains data that is -
Descriptive: Multiple points, such as name and location, come together to define an asset.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Static: The information doesn’t change much, and when it does, the shifts are subtle.
Valuable: Data stored within the directory is critical to core business functions, and it is touched over
and over again.
An LDAP query typically involves -
Session connection - The user connects to the server via. an LDAP port.
Request - The user submits a query, such as an email lookup, to the server.
Response - The LDAP protocol queries the directory, finds the information and delivers it to the user.
Completion - The user disconnects from the LDAP port.
Viva Questions:
1. What is the use of DNS?
2. Explain the concept of Resource Records in DNS.
3. Explain conditional forwarding in DNS.
4. Explain the various troubleshooting tools.
5. Describe the significance of the IP address.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
A proxy server is a computer that acts as an intermediary between a desktop computer and the internet and
allows a client machine to make an indirect connection to network servers and services. There are many
reasons to deploy the proxy server on network -
● To share internet connection on a LAN
● To speed up internet surfing
● To hide the IP address of the client computer for anonymous surfing
● To implement internet access control
● To scan outbound content
● To circumvent regional restrictions
Procedure
Step #1 Install Squid
Step #2: Verify the Squid Installation
Step #3: Start Squid and Configure it to Start on Boot
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LINUX LABORATORY
Viva Questions:
1. Explain the functions of a Firewall.
2. Explain the use of a VPN.
3. What is the use of port number?
4. Describe the significance of the proxy server.
5. Explain the advantages of installing Squid.
CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING