Linux Lab
Linux Lab
Linux lab
Submitted to:
Mr. Suneet Joshi
Assistant Professor
BACHELORS OF TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
Session-2021-22
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
CERTIFICATE
This is to certify that Mr./Ms ………. with RGPV Enrollment No. ….…. has satisfactorily
completed the course of experiments in ….LINUX LAB…. laboratory, as prescribed by Rajiv
Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal for ….5th …. Semester of the Computer
Science and Engineering Department during year 2020-2021
Signature of
Faculty In-charge
Experiment No. - 1
Theory:
>File Commands:
>Directory Commands:
o fg jobs - Brings the current job (or the specified jobs) to the foreground.
• file files - Determines and prints a description of the type of each specified file.
• find path -name pattern -print -----Searches the specified path for files with names
matching the specified pattern (usually enclosed in single quotes) and prints their names.
The find command has many other arguments and functions; see the online documentation.
• finger users - Prints descriptions of the specified users.
• free -Displays the amount of used and free system memory.
• ftp hostname: Opens an FTP connection to the specified host, allowing files to be
transferred. The FTP program provides subcommands for accomplishing file transfers; see
the online documentation.
• head files - Prints the first several lines of each specified file.
• ispell files - Checks the spelling of the contents of the specified files.
• kill process_ids
o kill - signal process_ids
o kill -l
o Kills the specified processes, sends the specified processes the specified signal
(given as a number or name), or prints a list of available signals.
• killall program
o killall - signal program:Kills all processes that are instances of the specified
program or sends the specified signal to all processes that are instances of the
specified program.
• mail - Launches a simple mail client that permits sending and receiving email messages.
• man title :man section title - Prints the specified man page.
• ping host - Sends an echo request via TCP/IP to the specified host. A response confirms
that the host is operational.
• reboot - Reboots the system (requires root privileges).
• shutdown minutes
o shutdown -r minutes
o Shuts down the system after the specified number of minutes elapses (requires root
privileges). The -r option causes the system to be rebooted once it has shut down.
• sleep time - Causes the command interpreter to pause for the specified number of seconds.
• sort files - Sorts the specified files. The command has many useful arguments; see the
online documentation.
• split file - Splits a file into several smaller files. The command has many arguments; see
the online documentation
• sync - Completes all pending input/output operations (requires root privileges).
• telnet host - Opens a login session on the specified host.
• top - Prints a display of system processes that's continually updated until the user presses
the q key.
• traceroute host - Uses echo requests to determine and print a network path to the host.
• uptime - Prints the system uptime.
• w - Prints the current system users.
• wall - Prints a message to each user except those who've disabled message reception.
Type Ctrl-D to end the message.
Experiment No. - 2
Theory:
+ (Addition) Adds values on either side of the `expr $a + $b` will give 30
operator
- (Subtraction) Subtracts right hand operand from left `expr $a - $b` will give -10
hand operand
* (Multiplication) Multiplies values on either side of the `expr $a \* $b` will give 200
operator
/ (Division) Divides left hand operand by right hand `expr $b / $a` will give 2
operand
% (Modulus) Divides left hand operand by right hand `expr $b % $a` will give 0
operand and returns remainder
!=(Not Equality) Compares two numbers, if both are [ $a != $b ] would return true.
different then returns true.
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 whereas, [$a==$b] is
incorrect.
All the arithmetical calculations are done using long integers.
Example
Here is an example which uses all the arithmetic operators –
Procedure:
Step 1 : Start with the header file .
Step 2: Initializes the two variables
Step 3: Perform the addition, subtraction, multiplication, division , comparison and
modulus operation
Step 4: Store the value in third variable.
Step 5: Print the value of third variable
#!/bin/sh
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
a + b : 30
a - b : -10
a * b : 200
b / a : 2
b % a : 0
a is not equal to b
Experiment 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:
To introduce the concept of text editing and the options regarding the control of the editor. Few
commands with cat :
Enter wc with -l option to print the no. of new lines in the file.
Enter wc with -L option to print the no. of characters in the longest line of the file
• Display All
Enter wc and filename without any option will show in the following column order: 1st
column- newlines count, 2nd column- words count and 3rd column- character count.
Just entering the wc command waits for you to enter some text and after you have written
the text press ctrl+d to end writing. wc counts number of lines, words and bytes.
10
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
$ cat capital.txt
Hyderabad
Itanagar
Dispur
Patna
Raipur
$ wc state.txt capital.txt
5 7 63 state.txt
5 5 45 capital.txt
10 12 108 total
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
$ cat capital.txt
Hyderabad
Itanagar
Dispur
Patna
Raipur
$ wc state.txt capital.txt
5 7 63 state.txt
5 5 45 capital.txt
10 12 108 total
11
12
Experiment No. - 4
Aim: Append ten more simple lines to the wlcc.txt file created above and split the appended file
into 3.
Theory:
Instead of overwriting another file, we can also append a source text file to another using the
redirection operator ">>".
For instance:
If another-text-file.txt does not already exist, it will be created and the contents
of wlcc.txt will be written to the new file.
• Split file
split: outputs fixed-size pieces of input INPUT to files named PREFIXaa, PREFIXab,
The default size for each split file is 1000 lines, and default PREFIX is "x". With no
INPUT, or when INPUT is a dash ("-"), read from standard input.Split the file wlcc.txt into
files beginning with the name new, each containing 300 lines of text.
13
14
Experiment No. - 5
Aim: Append Experiment No.5. 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:
grep command: grep is a command used to search text or searches the given file for lines
containing a match to the given strings or words. By default, grep displays the matching lines.
Code:
15
16
Experiment No. - 6
Aim: Create a program to find out the inode number of any desired filL
Theory:
First find out file inode number with any one of the following commands:
1. stat {file-name}OR
2. ls -il {file-name}
Code:
17
Experiment No. - 7
Aim: Study & use of the Command for changing file permissions.
Theory:
• Usage
• chown [OPTION] OWNER[:[GROUP]] FILE.
• The following options modify how a hierarchy is traversed when the -R option is also
specified. If more than one is specified, only the final one takes effect.
• -H if a command line argument is a symbolic link to a directory, traverse it.
• -L traverse every symbolic link to a directory encountered.
• -P do not traverse any symbolic links (default).
• chmod - change file access permissions
• chmod [-r] permissions filenames
• r Change the permission on files that are in the subdirectories of the directory that you are
currently in. Permission specifies the rights that are being granted. Below is the different
right that you can grant in an alpha-numeric format filenames. File or directory that are
associated with Permission.
• u - User who owns the file.
• g - Group that owns the file.
• - Other.
• a - All.
• r - Read the file.
• w - Write or edit the file.
• x - Execute or run the file as a program.
Code:
$ ls -li filename
$ ls -li /etc/resolv.conf
18
19
Experiment 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:
>Script: It will basically save everything printed on the terminal in that script session.
Script usere.ux
To logout of the screen session (stop saving the contents), just type exit.
Here is an example:
1. $ script usere.ux
2. $ ls
3. $ who –u(Show or list users logged in )
4. $ exit
5. $ cat usere.ux
Script also has many options e.g. running quietly -q (--quiet) without showing/saving program
messages, it can also run a specific command -c (--command) rather than a session, it also has
many other options
20
Experiment No. - 9
Theory:
To introduce the concept of text editing vi editor and the options regarding the control of the editor.
To open a file in vi editor run the command: vi filename .shTo write or modify something in file
go to insert mod by pressing anyone of three keys a/i/oAfter writing in file following modes for
quit from editor.
>Operation Modes
While working with the vi editor, we usually come across the following two modes −
• Command mode − This mode enables you to perform administrative tasks such as saving
the files, executing the commands, moving the cursor, cutting (yanking) and pasting the
lines or words, as well as 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 placed in the file.
vi always starts in the command mode. To enter text, you must be in the insert mode for which
simply type i. To come out of the insert mode, press the Esc key, which will take you back to the
command mode.
Hint − If you are not sure which mode you are in, press the Esc key twice; this will take you to
the command mode. You open a file using the vi editor. Start by typing some characters and then
come to the command mode to understand the difference.
>Getting Out of vi
The command to quit out of vi is :q. Once in the 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 use :wq and return.
The easiest way to save your changes and exit vi is with the ZZ command. When you are in the
command mode, type ZZ. The ZZ command works the same way as the :wq command.
21
Experiment No. – 10
Aim: Write a shell script that accepts any number of arguments and prints them in the reverse
order.
Theory:
Procedure:
Step 1 : Start with the header file .
Step 2: Initializes the two variables: Sd and rev
Step 3: Perform the logic to reverse the number.
Step 4: Store the value in third variable.
Step 5: Print the value of third variable
Code:
echo "no of arguments:$#"
echo "arguments in reverse order:"
for i in $*
do
j=$i" "$j
done
echo $j
OR
22
Experiment No. – 11
Aim: Write a shell script to find the smallest of three numbers that are read from the keyboard.
Theory:
Procedure:
Step 1 : Start with the header file .
Step 2: Initializes the three variables: a,b,c
Step 3: Perform the logic to know the smallest number among number entered by user.
Step 4: Store the value in third variable.
Step 5: Print the value of third variable
Code:
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
23
24
Experiment No. – 12
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.
Theory:
Procedure:
Code:
25
Experiment No. – 13
Theory:
An Apache Tomcat is an open source web application server which supports J2ee Servlet us,
JavaServer, Pages (JSP) and API's. Tomcat should not be confused with Apache web server
which an HTTPweb server.
Servlet is defined as a way add dynamic content to a Web server using the Java platform. A
servlet container is a compiled, executable program. The servlet container name of Tomcat is
called as Catalina.
>Samba
Samba is the standard open source Windows interoperability suite of programs for Linux. It
implements the server message block (SMB) protocol. Modern versions of this protocol are also
known as the common Internet file system (CIFS) protocol. It allows the networking of
Microsoft Windows, Linux, UNIX, and other operating systems together, enabling access to
Windows-based file and printer shares. Samba’s use of SMB allows it to appear as a Windows
server to Windows clients.
In order to use Samba, first ensure the samba package is installed on your system by running,
as root:
26
>Introduction to Samba
Samba is an important component to seamlessly integrate Linux Servers and Desktops into
Active Directory (AD) environments. Samba can do:
• Serve directory trees and printers to Linux, UNIX, and Windows clients
• Assist in network browsing (with NetBIOS)
• Authenticate Windows domain logins
• Provide Windows Internet Name Service (WINS) name server resolution
• Act as a Windows NT-style Primary Domain Controller (PDC)
• Act as a Backup Domain Controller (BDC) for a Samba-based PDC
An icon appears for each available SMB workgroup or domain on the network.
2. Double-click one of the workgroup or domain icon to view a list of computers within the
workgroup or domain.
3. An icon exists for each machine within the workgroup. Double-click on an icon to view the
Samba shares on the machine. If a user name and password combination is required, you are
prompted for them.
27
Experiment No. – 14
Theory:
Domain Name Service (DNS) is an internet service that maps IP addresses to fully qualified
domain names (FQDN) and vice versa.
BIND is the most common program used for maintaining a name server on Linux.
1. Network Information
2. Install Bind
3. Configure Cache NameServer
4. Test the Cache NameServer
5. Configure Primary/Master Nameserver
6. Build the Forward Resolution for Primary/Master NameServer
7. Test the DNS server
28
Experiment No. – 15
Theory:
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 why you might want to include a proxy server on your network:
Procedure
The main area of the Firewall Configuration tool consists of a list of categories on in the left hand
pane and the current corresponding settings for that category in the right hand panel.
The Trusted Services category essentially defines which TCP/IP ports are open to traffic on the
firewall. There a number of so called known ports which are assigned to specific servers (such as
port 80 for a web server).
SSH - The secure shell provides an encrypted mechanism for allowing password protected remote
access to your system. With SSH you can remotely log into to your system, copy files to and from
your system and another systems and perform remote execution of programs. If you need remote
access to your system you will need to activate this. If you do not need remote access leave this
disabled. Note that the ssh server is not installed by default on Fedora Linux.
Telnet - Telnet provides remote terminal access to your system. It does not use encryption and use
is strongly discouraged. Leave this disabled and use SSH instead for remote access.
WWW (HTTP) - If you are hosting a web server on your Fedora Linux System you will need to
enable HTTP traffic through the firewall to enable web page requests to reach the http server. If
you do not plan to host a web server, leave this disabled. Note that the Apache web server is not
29
installed by default on Fedora Linux unless you specifically requested during the installation
process.
Mail (SMTP) - Specifies whether the firewall blocks Simple Mail Transfer Protocol traffic. This
is only necessary if you are hosting a mail server on your Fedora Linux system. If you only use a
mail client to download email from a POP3 or IMAP server you can safely leave this disabled.
Note that the SMTP server is not installed by default on Fedora Linux.
FTP - Controls whether File Transfer Protocol traffic is permitted through the firewall. Unless you
plan to set up an ftp server (unlikely for typical users) leave this option disabled. Note that the FTP
server is not installed by default on Fedora Linux.
Samba - The Samba service is allows files and printers to be shared between Linux and Windows
systems. If this traffic is blocked in the firewall, it will not be possible to use Samba on this system.
30