Practicals of Linux 2017 (CS - 5006)
Practicals of Linux 2017 (CS - 5006)
Practicals of Linux 2017 (CS - 5006)
Introduction to Linux
Linux is fully customizable free operating system and is supported by all kinds of
hardware components. Due to advent open source feature of Linux, everyone can
download the source code of Linux and modify it. On the server side Linux is a renowned
OS for its stability and reliability. Day by day Linux is getting more popular and user
friendly. Modern Linux is not only supported by high end server, workstations and home
PC but can also run on various gadgets.
Linux is totally UNIX kernel but not fully UNIX OS because it does not include
applications like file system, Window system, text editor, Compiler and so on.. Whole
Linux distribution is a collection of Linux Kernel, GUI, GNU C/C++ compiler, text
editors and various applications under GPL. Linux uses only POSIX (Portable Operating
System Interface Standards) of UNIX. which are standards specified by IEEE computer
society for maintaining compability between OS.
It needs standard GNU C compiler and GPL (General Purpose License). GNU is
collection of computer software that can be used in building an OS like UNIX or
Linux.and makes it free to use for everyone. Various GNU components are used to
develop Linux like GNU compiler, debugger and hardware. Linux was licensed under the
GPL. Without paying any charge, you can download source code of Linux to use, share
and modify it. GPL (General Public License) uses free license software which provides
freedom to run, share, modify and study it.
Before we discuss Linux in brief, mentioned below are some of its advantages: Open
Source
-More powerful
-Well supported
-Well Secure
1
Features of Linux
Linux is fully featured OSand adopts various features from different UNIX
versions. Multithreading
Linux is supported by multithreading environment. More than one thread can run at the
same time in Linux. Thread is a small code within the process. I will briefly explain about
thread in another tutorial.
Monolithic kernel
File System
Whole Linux kernel is based on file system architecture. Linux supports many file types
such as a directory file, link, pipe, named pipe, special file and block device file. Each file
type has its own characteristics and features. File system is not only holding the data of
file but also contains the structure and informationof the file.
Multiuser Capability
Linux OS shares the same resources like memory, hard disk etc. for multi users. Multi
users can access same resource using individual terminal (i.e. client PC).
2
Experiment 02
Directory structure of Linux
1. / – Root
Every single file and directory starts from the root directory.
Only root user has write privilege under this directory.
Please note that /root is root user’s home directory, which is not same as /.
3
This is a virtual filesystem with text information about system resources. For
example: /proc/uptime
4
13. /opt – Optional add-on Applications
opt stands for optional.
Contains add-on applications from individual vendors.
add-on applications should be installed under either /opt/ or /opt/ sub-directory.
5
Experiment 03
VI Editor
The VI editor is the most popular and classic text editor in the Linux family. Below, are
some reasons which make it a widely used editor –
Nowadays, there are advanced versions of the vi editor available, and the most popular
one is VIM which is Vi Improved. Some of the other ones are Elvis, Nvi, Nano, and
Vile. It is wise to learn vi because it is feature-rich and offers endless possibilities to edit
a file.
To work on VI editor, you need to understand its operation modes. They can be divided
into two main parts.
Command mode:
Insert mode:
vi <filename_NEW> or <filename_EXISTING>
6
& If you specify an existing file, then the editor would open it for you to edit. Else, you
can create a new file.
7
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
8
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
vi Editing commands
Note: You should be in the "command mode" to execute these commands. VI editor
is case-sensitive so make sure you type the commands in the right letter-case.
Keystrokes Action
dd Delete line
3dd Delete 3 lines.
C Delete contents of a line after the cursor and insert new text. Press ESC key to end
insertion.
dw Delete word
4dw Delete 4 words
Cw Change word
R Replace character
S Substitute entire line and begin to insert at the beginning of the line
Make sure you press the right command otherwise you will end up making undesirable
changes to the file. You can also enter the insert mode by pressing a, A, o, as required.
9
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
You need to be in the command mode to move within a file. The default keys for
navigation are mentioned below else; You can also use the arrow keys on the
keyboard.
Keystroke Use
K Move cursor up
You should be in the command mode to exit the editor and save changes to the file.
Keystroke Use
10
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 4
Steps Create & execute shell script
#!/bin/bash
To execute Script
(2) #./simplescript
Output
11
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 5
Shell script for performing mathematical operations
#!/bin/bash
a=10
b=5
echo Addition
c=expr $a+$b
echo Substraction
d=expr $a-$b
echo Multiplication
e=expr $a*$b
echo Division
f=expr $a/$b
Output
12
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 6
Shell script for performing mathematical operations
using inputs
#!/bin/bash
echo Addition
c=expr $a+$b
echo Substraction
d=expr $a-$b
echo Multiplication
e=expr $a*$b
echo Division
f=expr $a/$b
Output
13
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 7
Shell script to print table
#!/bin/bash
echo Table
read n
do
done
Output
14
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 8
Shell script to implement nested loop
#!/bin/bash
echo Steps
do
do
echo -n “|”
done
echo “_”
done
Output
15
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 9
Shell script to print system information
#!/bin/bash
Output
16
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 10
Shell Script to print file details
#!/bin/bash
Output
17
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
Experiment 11
Starting with the Red Hat Enterprise Linux 3.0 release (and in CentOS
Enterprise Linux), the FTP server (wu-ftpd) is no longer available with
xinetd. It has been replaced with vsftp and can be started from
/etc/init.d/vsftpd as in the following:
# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
If you want the vsftpd service to start and stop when recycling (rebooting)
the machine, you can create the following symbolic links:
# ln -s /etc/init.d/vsftpd /etc/rc3.d/S56vsftpd
# ln -s /etc/init.d/vsftpd /etc/rc4.d/S56vsftpd
# ln -s /etc/init.d/vsftpd /etc/rc5.d/S56vsftpd
Configure Telnet for root logins :Simply edit the file /etc/securetty
and add the following to the end of the file:
pts/0
pts/1
pts/2
pts/3
18
ASCT BHOPAL Linux & Shell Programming (CS - 5006)
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
This will allow up to 10 telnet sessions to the server as root.
Configure FTP for root logins Edit the files /etc/vsftpd.ftpusers and
/etc/vsftpd.user_list and remove the 'root' line from each file.
19