0% found this document useful (0 votes)
26 views62 pages

Linux Manual

The document is a laboratory manual for the LINUX Administration Lab (CS1206) at Sanketika Vidya Parishad Engineering College, outlining the course objectives, outcomes, and various experiments to be conducted. It details the vision and mission of the department, program educational objectives, and program specific outcomes, emphasizing the importance of practical skills in Linux. Additionally, it includes general laboratory instructions, a syllabus of experiments, and an introduction to the Linux operating system and its components.

Uploaded by

n44943916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views62 pages

Linux Manual

The document is a laboratory manual for the LINUX Administration Lab (CS1206) at Sanketika Vidya Parishad Engineering College, outlining the course objectives, outcomes, and various experiments to be conducted. It details the vision and mission of the department, program educational objectives, and program specific outcomes, emphasizing the importance of practical skills in Linux. Additionally, it includes general laboratory instructions, a syllabus of experiments, and an introduction to the Linux operating system and its components.

Uploaded by

n44943916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Sanketika Vidya Parishad Engineering College

LINUX ADMINISTRATION LAB


(CS1206) ___
_LABORATORY MANUAL & RECORD
B.Tech(Common for CSE, AI, AI&ML and AI&DS)
(With effect from 2022-23 admitted batches)
(I YEAR- IISEM)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SANKETIKA VIDYA PARISHAD ENGINEERING COLLEGE


(APPROVED BY AICTE, AFFILIATED TO ANDHRAUNIVERSITY, ACCREDITED
BY NAAC - A GRADE, ISO 9001:2015 CERFIFIED) PM PALEM,
VISAKHAPATNAM-41,
www.svpce.edu.in

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

INSTITUTE VISION AND MISSION

VISION
To be a premier institute of knowledge of share quality research and development technologies towards
national buildings

MISSION
• Develop the state of the art environment of high quality of learning
• Collaborate with industries and academic towards training research innovation and entrepreneurship
• Create a platform of active participation co-circular and extra-circular activities

DEPARTMENT VISION AND MISSION


VISION
To impart quality education for producing highly talented globally recognizable techno carts and
entrepreneurs with innovative ideas in computer science and engineering to meet industrial needs and
societal expectations

MISSION
• To impart high standard value-based technical education in all aspects of Computer Science
and Engineering through the state of the art infrastructure and innovative approach.

• To produce ethical, motivated, and skilled engineers through theoretical knowledge and
practical applications.

• To impart the ability for tackling simple to complex problems individually as well as in a team.

• To develop globally competent engineers with strong foundations, capable of “out of the box”
thinking so as to adapt to the rapidly changing scenarios requiring socially conscious green
computing solutions.

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)


Graduates of B.Tech in computer science and Engineering Programme shall be able to

PEO1: Strong foundation of knowledge and skills in the field of Computer Science and Engineering.
PEO2: Provide solutions to challenging problems in their profession by applying computer engineering
theory and practices.
PEO3: Produce leadership and are effective in multidisciplinary environment.

PROGRAMME SPECIFIC OUTCOMES (PSOs)


PSO1: Ability to design and develop computer programs and understand the structure and development
methodologies of software systems.
PSO2: Ability to apply their skills in the field of networking, web design, cloud computing and data
analytics.
PSO3: Ability to understand the basic and advanced computing technologies towards getting employed or
to become an entrepreneur

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


PROGRAM OUTCOMES
1. Engineering Knowledge: Apply the knowledge of mathematics, science,engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
2. Problem Analysis: Identify, formulate, research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering
sciences.
3. Design/Development of Solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
4. Conduct Investigations of Complex Problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern Tool Usage: Create, select, and apply appropriate techniques, resources, and
modernengineeringandITtoolsincludingpredictionand modellingto complexengineering activities with an
understanding of the limitations.
6. The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and Sustainability: Understand the impact ofthe professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of,and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and Team Work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, give and receive clear instructions.
11. Project Management and Finance: Demonstrate knowledge andunderstandingofthe
engineeringandmanagementprinciplesandapplythesetoone’sown work,asa member and leader in a team, to
manage projects and in multidisciplinary environments.
12. Life-Long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technologicalchange.

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

COURSE OBJECTIVES
• To understand LINUX operating system and its internals.
• To understand LINUX file system structure and its operations.
• To understand LINUX shell environment and its programming.
• To understand communication in LINUX and the corresponding primitives.

COURSE OUTCOMES(CO)

After completion of the course, students will be able to:

• The student learns about LINUX features for multiuser, multitasking capabilities.
• The student learns about file system organization, file and directory manipulation, setting file
permissions, and disk free space administration.
• The student learns about writing shell scripts for different applications.
• The student learns about how users communicate with each other in LINUX environment.

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING GENERAL


_________LABORATORY INSTRUCTIONS

1. Students are advised to come to the laboratory at least 5 minutes before (to the starting time), those who
come after 5 minutes will not be allowed into the lab.
2. Plan yourtask properly much before to the commencement, come prepared to the lab with the synopsis /
program / experiment details.
3. Studentshouldenterintothelaboratorywith:
a. Laboratory observation notes with all the details (Problem statement, Aim, Algorithm, Procedure,
Program, Expected Output, etc.,) filled in for the lab session.
b. Laboratory Record updated up to the last session experiments and other utensils (if any) needed in the lab.
c. ProperDresscodeandIdentitycard.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system allotted to you
by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab observation note book, and
get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must maintain the discipline
and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded systems, which should be utilized
properly.
8. Students/Facultymust keeptheir mobilephonesinSWITCHEDOFFmodeduringthe lab sessions. Misuse of
the equipment, misbehaviors with the staff and systems etc., will attract severe punishment.
9. Students must take the permission of the faculty in case ofany urgency to go out; if anybody found loitering
outside the lab / class without permission during working hours will be treated seriously and punished
appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer systembefore he/she leaves the labafter
completing the task(experiment) inallaspects. He/she must ensure the system/ seat is kept properly

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

CS1206 LINUX ADMINISTRATION LAB Syllabus

EXPERIMENTS

1) Study and practice on file system / handling files with commands, syntax, usage,
application.
2) Practice on vi editor.
3) Study and practice on redirection operators with relevant commands, syntax, usage,
application.
4) Study and practice on filters with relevant commands, syntax, usage, application.
5) Study and practice on Backup with relevant commands, syntax, usage, application.
6) Study and practice on internet related commands, syntax, usage, application.
7) Study and practice on shells/shell programming with relevant programming constructs,
syntax, usage, application.
8) Study and practice on awk with relevant commands, syntax, usage, application.
9) Study and practice on regular expressions and the grep family with relevant commands,
syntax, usage, application.
10) Study and practice on compilation process of C programs under UNIX.

References:
1. Unix concepts and applications by Sumitabha Das, TMH Publications.
2. Shell programming by Yashwanth Kanetkar.

Department of Computer Science and Engineering R. Bhanu Sankar


Sanketika Vidya Parishad Engineering College

TABLEOF CONTENTS

Sl. CONTENT Page


No No
Introduction to LINUX 1-3

1 Study and practice on file system / handling files with commands, 4-7
syntax, usage, application
2 Practice on vi editor. 8-12
3 Study and practice on redirection operators with relevant commands, 13-14
syntax, usage, application.
4 Study and practice on filters with relevant commands, syntax, usage, 15-20
application.
5 Study and practice on Backup with relevant commands, syntax, usage, 21-22
application.
6 Study and practice on internet related commands, syntax, usage, 23-25
application.
7 Study and practice on shells/shell programming with relevant 26-36
programming constructs, syntax, usage, application.
8 Study and practice on awk with relevant commands, syntax, usage, 37-38
application.
9 Study and practice on regular expressions and the grep family with 39-40
relevant commands, syntax, usage, application.
10 Study and practice on compilation process of C programs under UNIX. 41-43
Viva-Voce Questions 44-54
Sanketika Vidya Parishad Engineering College
INTRODUCTIN TO LINUX

Linux is an open-source operating system. It is like Windows, Mac, Android, etc. Unix is
also an operating system like Linux. It is a commercial OS. It consists of three parts:
Kernal, Shell, and Programs. Most of the Unix and Linux commands are similar in nature.
Linux is an open- source Unix- like operating system-based family on the Linux kernel, and
the OS kernel was first published on 17th September 1991 by LinusTorvalds.

Components of Linux System


Linux Operating System has primarily three components
• Kernel − Kernel is the core part of Linux. It is responsible for all major activities
of this operating system. Itconsists of various modules and it interacts directly with
the underlying hardware. Kernel provides the requiredabstractiontohide
lowlevelhardwaredetailstosystemor applicationprograms.
• System Library − System libraries are special functions or programs using which
application programs or system utilities accesses Kernel's features. These libraries
implement most of the functionalities of the operatingsystem and do not requires
kernel module's code access rights.
• SystemUtility− System Utility programs are responsible to do specialized, individual
level tasks.

KernelMode vs UserMode
Kernel component code executes in a special privileged mode called kernel mode with
full access to all resources of the computer. This code represents a single process,executes
in a single address space, and does not require any context switch hence is very efficient
and fast. The kernel runs each process and provides system services to processes,
providing protected access to hardware to processes.

1
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Support code that is not required to run in kernel mode is in System Library. User
programs and other system programs work in User Mode which has no access to the
system hardware and kernel code. User programs/ utilities use System libraries to access
Kernel functions to get the system's low-level tasks.
BasicFeatures
Following are some of the important features of the Linux OperatingSystem.
• Portable − Portability means software can work on different types of hardware in
the same way. Linux kernel and application programs support their installation on
any kind of hardware platform.
• Open Source−Linux source code is freely available and it is a community-based
development project. Multiple teams work in collaboration to enhance the
capability of the Linux operating system and it is continuously evolving.
• Multi-User − Linux is a multi user system means multiple users can access system
resources like memory/ram/application programs at the same time.
• Multiprogramming − Linux is a multiprogramming system that means multiple
applications can run at thesametime.
• Hierarchical File System − Linux provides a standard file structure in which
system files/ user files arearranged.
• Shell − Linux provides a special interpreter program that can be used to execute
commands of the operatingsystem. It can be used to do various types of operations,
call application programs. etc.
• Security−Linux provides user security using authentication features like password
protection/controlled access to specific files/encryption of data.
Architecture
The following illustration shows the architecture of a Linux system−

2
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

The architecture of a Linux System consists of the following layers−

• Hardware layer−Hardware consists of all peripheral devices(RAM/HDD/ CPU etc).


• Kernel−It is the core component of the OperatingSystem, interacts directly with
hardware, and provides low-level services to upper-layer components.
• Shell−An interface to the kernel, hiding the complexity of the kernel's functions
from users. The shell takes commands from the user and executes the kernel's
functions.
• Utilities −Utility programs that provide the user with most of the functionalities of
operatingsystems.

3
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Ex-1: Study and practice file system/handling files with commands, syntax, usage, and
application.

A file system is a method or structure used by an operating system to organize and store data
on storage devices, such as hard drives, solid-state drives, or optical discs. It provides a logical
and efficient way to manage files, directories, and their associated metadata.
In Linux, most of the operations are performed on files. And to handle these files Linux
has directories also known as folders which are maintained in a tree-like structure. Though,
these directories are also a type of file themselves. Linux has 3 types of files:

Regular Files: It is the common file type in Linux. it includes files like – text files, images,
binary files, etc. Such files can be created using the touch command. They consist of the
majority of files in the Linux/UNIX system. The regular file contains ASCII or Human
Readable text, executable program binaries, program data and much more.

Directories: Windows call these directories as folders. These are the files that store the list of
file names and the related information. The root directory(/) is the base of the system, /home/
is the default location for user’s home directories, /bin for Essential User Binaries, /boot –
Static Boot Files, etc. We could create new directories with mkdir command.

Special Files: Represents a real physical device such as a printer which is used for IO
operations. Device or special files are used for device Input/Output(I/O) on UNIX and Linux
systems. You can see them in a file system like an ordinary directory or file.

1.Linux Directory Commands


1. PwdCommand
The pwd command is used to display the location of the current working directory.
Syntax:
pwd
Output:

2. MkdirCommand
The mkdir command is used to create a new directory under any directory.
Syntax:
mkdir
<directory
name>

4
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Output:

3. rmdirCommand
The rmdir command is used to delete a directory.
Syntax:
rmdir
<directory
name>
Output:

4. ls
Command
The ls command is used to display a list of content of a directory.
Syntax:
ls
Output:

5. cdCommand
The cd command is used to change the current directory.
Syntax:
cd
<directory
name>
Output:

2.LinuxFilecommands
6. touchCommand
The touch command is used to create empty files. We can create multiple empty files by
5
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
executing it once.
Syntax:
touch<file name>
touch<file1><file2>....

Output:

7. catCommand
The cat command is a multi-purpose utility in the Linux system.It can be used to create
a file, display content of the file, copy the content of one file to another file, and more.
Syntax:
cat[OPTION]...[FILE]..
To create a file, execute it as follows:
cat ><filename>
//Enterfilecontent
Press "CTRL+ D" keys to save the file. To display the content of the
file, execute it as follows:cat<file name>
Output:

8. rmCommand
The rm command is used to remove a file.
Syntax:
rm<filename>
Output:

9. cpCommand
The cp command is used to copy a file or directory.
Syntax:
Tocopyinthesame directory:
cp <existing file

6
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
name><new file name>
Output:

10. mvCommand
The mv command is used to move a file or a directory form one location to another
location.
Syntax:
mv <file
name><directory
path>
Output:

7
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Ex-2:Practiceonvieditor.
WhatistheVIeditor?
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–
1) It is available in almost all Linux Distributions
2) It works the same across different platforms and Distributions
3) It is user-friendly. Hence, millions of Linux users love it and use it for their editing needs
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 end less 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.
vi Command mode:
• The vi editor opens in this mode, and it only understands commands

• In this mode, you can, move the cursor and cut, copy, paste the text

• This mode also saves the changes you have made to the file

• Commands are case sensitive.


• You should use the right letter case.vi Editor
Insert mode:
• This mode is for inserting text in the file.
• You can switch to the Insert mode from the command mode by pressing ‘i’ on the
keyboard
• Once you are in Insertmode, any key would be taken as an input for the file on which
you are currently working.
• To return to the command mode and save the changes you have made you need to
press the Esc key
How to use vi editor
To launch the VIEditor -Open the Terminal (CLI) and type
vi<filename_NEW>or<filename_EXISTING>
And if you specify an existing file, then the editor would open it for you to edit. Else, you

8
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
can create a new file.

9
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

VIEditingcommands
• i–Insert at cursor(goesintoinsert mode)

10
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
• a–Writeaftercursor(goesintoinsertmode)
• A– Writeattheendofline(goesintoinsertmode)
• ESC–Terminateinsertmode
• u –Undo last change
• U–Undo all changes to the entire line
• o–Open a new line (goes into insert mode)
• dd–Delete line
• 3dd–Delete 3lines.
• D– Delete contents of line after the cursor
• C–Delete contents of a line after the cursor and insert newtext. Press ESC key to end
insertion.
• dw–Delete word
• 4dw– Delete4 words
• cw–Change word
• x –Delete character at the cursor
• r–Replace character
• R–Overwrite characters from cursor onward
• s –Substitute one character under cursor continue to insert
• S–Substitute entire line and begin to insert at the beginning of the line
• ~ – Change case of individual character
Note: You should be in the “command mode” to execute the se commands. VI editor is
case-sensitive so make sure you type the commands in the right letter-case.
Make sure you press the right command otherwise you will end up making undesirable
changes to the file. You can also enter the insertmode by pressing a, A , o , as required.
Moving with in a file
• k–Move cursor up

• j–Move cursor down


• h– Move cursor left
• l– Move cursor right

You need to be in the command mode to move with in a file. The default keys for
navigation are mentioned below else; You can also use the arrow keys on the
keyboard.

11
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Saving and Closing the file
• Shift+zz–Save the file and quit

• :w–Save the file but keep it open


• :q!–Quit vi and do not save changes
• :wq–Save the file and quit
You should be in the command mode to exit the editor and save changes to the file.
To create a file with Vi editor, execute the below command:
Vi test10.txt
The above command will open the Vi editor. Press I key for the insertmode and enter
the file content. Press Esc key and :wq to save and exit the file from the editor.
To display the file information, execute the below command:
ls -ltest10.txt
To display the file content, execute the below command:
Cat test10.txt

Consider the below output:

12
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Ex-3: Study and practice on redirection operators with relevant commands,
syntax, usage andapplication.
Linux I/O Redirection
Redirection can be defined as changing the way from where commands read input to
where commands sends output. You can redirect input and output of acommand.
For redirection, meta characters are used.Redirection can be into a file (shell meta
characters are angle brackets'<','>') or a program( shell meta characters are pipe
symbol'|').
Standard Streams In I/O Redirection
The bash shell has three standard streams in I/O redirection:
o standardinput(stdin):The stdinstream is numbered as stdin(0).The bash shell
takes input from stdin. By default, keyboard is used as input.
o standardoutput(stdout):The stdout stream is numbered as stdout(1).The bash
shell sends output to stdout. Output goes to display.
o standarderror(stderr):The stderr stream is numbered as stderr(2).The bash shell
sends error message to stderr .Error message goes to display.

1. LinuxInputRedirection
<stdin
The bash shell uses stdin to take input. In input redirection, a file is made in put to the
command and this redirection is done with the help of '<'sign.
Syntax:
cat<<file
Name>
Exampl:
cat<file.txt

Look at the above snapshot, command "cat<file.txt" has taken 'file.txt' as input and display
edits content.

13
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
2. LinuxOutputRedirection
Output redirection is used to put output of one command into a file or into another
command.
> stdout
The stdout is redirected with a '>' greaterthan sign.When shell meets the '>' sign, it will
clear the file (as you already know).
Example:
Echo Hello everyone. > afile.txt

Look at the above snapshot, greater than sign'>'redirects the command 'echo' output into a
file 'afile.txt'.
3. Linux ErrorRedirection
2>stderr
Command '2>' redirects the error of an output.It helps us you to keep our display less messy
by redirecting error messages.
Example:
zchohyii2>/dev/null

Look at the above snapshot, by using command "zcho hyii2>/dev/null" (here echo
command is wrong), we didn't get any error message. But when we use command "zcho
hyii" error message is displayed in the terminal. Hence, '2>' redirects the error message
in the mentioned directory keeping your terminal error message free.

14
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Ex-4:Study and practice on filters with relevant commands, syntax, usage and
applications.
Linux Filters
Linux Filter commands accept input data from stdin (standard input) and produce
output on stdout (standard output).It transforms plain-text data into a meaningful way
and can be used with pipes to perform higher operations.
These filters are very small programs that are designed for a specific function which can be
used as building blocks.
Linux Filter Commands
1. cat
2. grep
3. sort
4. Number sorting
5. Head
6. tail
7. Tac
8. uniq
9. wc
10. sed
1. LinuxCatFilters
When cat command is used inside pipes, it does nothing except moving stdin to stout.
Syntax:
cat <fileName> | cat or tac |cat
or tac |. . .Example:
catweeks.txt|tac|cat|cat|tac

15
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Look at the above snapshot, output of one 'cat' or 'tac' command is passing on to another as
input.
2. Grep Command in Linux/Unix
The 'grep' command stands for "global regular expression print". Grep command filters
the content of a file which make sourse arch easy.
Syntax:
grep<searchWord>
<filename>
Example: grep 9
marks.txt

Look at the above snapshot, grep command do the same work as earlier example but
without pipe.
Grep options
O grep-v M:The 'grep-v' command displays lines not matching to the specified word.
Syntax:
grep -v <searchWord>
<fileName>
Example:
grep-v 9 marks.txt

Look at the above snapshot , command "grep-v 9 marks.txt" displays lines


which don't contain our searchword '9'.
O grep -i : The 'grep -i' command filters output in a case-insensitive way.
Syntax:
grep -i <searchWord>
<fileName>
16
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Example:
grep -i red exm.txt

Look at the above snapshot, command "grep-I red exm.txt" displays all lines
containing 'red' whether in uppercase or lowercase.

3. Linux sort
The 'sort' command sorts the file content in alphabetical order.
Syntax:

sort <fileName>
Example:
sortweeks.txt

Look at the above snapshot, the 'sort' command has sorted the file 'weeks.txt' in alphabetical
order.
4. Numeric Sorting
Numeric sorting is different from alphabetical sorting. For numeric sorting option 'n' is
17
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
used along with the column number if required.
Syntax:

sort -n -
k<columnNumber>
<fileName>Example:

sort-n-k2marks.txt

5. headCommand
The head command is used to display the content of a file. It displays the first 10 lines of a
file.
Syntax:
head
<file
name>
Output:

6. Tail Command
The tail command is similar to the head command. The difference between both
commands is that it displays the last ten lines of the file content. It is useful for reading
the error message.
Syntax:
18
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
tail
<file
name
Output

7.tacCommand
The tac command is the reverse of cat command, as its name specified. It displays the
file content in reverse order (from the lastline).
Syntax:
tac
<file
name
Output:

8. uniq Command
The uniq command is used to form a sortedlist in which every word will occur only once.
Syntax:
command<fileName>|uniq

19
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Output:

9.wc Command
The wc command is used to count the lines, words, and characters in a file.
Syntax:
wc
<file
name
Output

10.sed command
The sed command is also known as streameditor. It is used to edit files using a regular
expression. It does not permanently edit files; instead, the edited content remains only on
display. It does not affect the actual file.
Syntax:
command|sed's/<oldWord>/<newWord>/'
Output:

20
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

EX-5 : STUDY AND PRACTICE ON BACKUP WITH RELEVENT COMMANDS,


COMMANDS, SYNTAX, USAGE AND APPLICATIONS
In Linux, backups are essential for data protection and disaster recovery. They involve
creating copies of important files, directories, or entire systems and storing them in a safe
location. Backups help safeguard against data loss caused by hardware failures, software
issues, accidental deletions, or even natural disasters.
There are various methods and tools available for performing backups in Linux. Some of
the commonly used ones are:
TAR COMMAND :
The tar command in Linux is a popular utility used for archiving files and directories into
a single file. The name "tar" stands for "tape archive," as it was originally designed for use
with tape drives. However, it is now commonly used for creating and extracting archive files
on various storage media, including disk drives.
The basic syntax of the tar command is as follows:
tar [options] archive_name.tar files_or_directories_to_archive
Here are some commonly used options with the tar command:
c: Create a new archive.
x: Extract files from an archive.
v: Verbose mode, which displays the files being processed.
f: Specifies the filename of the archive to create or extract from. Always put this option at
the end of the command followed by the archive name.
z: Compress the archive using gzip.
j: Compress the archive using bzip2.
t: List the contents of an archive without extracting.
r: Append files to an existing archive.
u: Update the archive, adding files only if they are newer than the existing ones in the
archive.
A: Concatenate archives.
ARCHIVE : it refers to a collection of historical documents, records or other materials that
one preserved and stored for future reference and research. And it makes the record inactive
DIFFERENCE BETWEEN GZIP AND BZIP2
gzip: It offers moderate to good compression ratios and is generally faster than bzip2.
bzip2: It provides higher compression ratios than gzip, meaning that the resulting
compressed files are often smaller. However, this comes at the cost of increased compression
time compared to gzip.

21
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
SYNTAX :
Create a new archive named "archive.tar" from a file called "file1.txt" and a directory called
"my_directory":
$ tar -cvf archive.tar file1.txt my_directory
Extract files from the "archive.tar":
$ tar -xvf archive.tar
Create a gzipped archive named "archive.tar.gz" from a directory "my_files":
$ tar -czvf archive.tar.gz my_files
Extract files from a gzipped archive "archive.tar.gz":
$ tar -xzvf archive.tar.gz
Remember, the order of options is essential. For example, when creating an archive, -cvf
must be used together, where -c specifies the "create" mode, -v enables verbose mode, and -f
indicates the filename to be used. Similarly, when extracting, use -xvf together to indicate
"extract," enable verbose mode, and specify the filename.
You can check the manual page for tar for more details and additional options by tar in
your terminal.

22
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

EX-6 :Study and practice on internet related commands,syntax, usage, application

Every computer is connected to some other computer through a network whether


internally or externally to exchange some information. This network can be small as some
computers connected in your home or office, or can be large or complicated as in large
University or the entire Internet.

Maintaining a system's network is a task of System/Network administrator. Their task includes


network configuration and troubleshooting.

finger command:

The finger command in Linux is used to display information about users on a Unix-
like operating system. It provides details about users who are currently logged into the
system or information about a specific user. However, please note that the usage of the finger
command might vary depending on the Linux distribution and the system's configuration.
The basic syntax of the finger command is as follows:
finger [username]
If you run the command without specifying a username, it will display information about all
users who are currently logged in. If you provide a username as an argument, it will show
detailed information about that specific user.
Here is an example of using the finger command:
finger
This command might output something like:
Login Name Tty Idle Login Time Office Office Phone
user1 John Doe tty1 4:25 Aug 9 10:00 (:0)
user2 Jane Smith pts/0 Aug 9 11:30 (192.168.1.2)
user3 Alice Johnson pts/1 1:23 Aug 9 12:15 (192.168.1.3)

In this example, you can see the logged-in users' login names, real names, terminal types
(e.g., tty1 or pts/0 for pseudo-terminals), idle times, and login times.
NOTE:- the finger command might not be available on all Linux distributions by default,
and its usage might be restricted for security reasons.

rlogin command:

The rlogin command in Linux is used to establish a remote login session between your
local machine and a remote machine. It allows you to log in to the remote machine and work
as if you were sitting directly in front of it. However, as I mentioned before, rlogin is
considered insecure due to the way it transmits data, and it's recommended to use more
secure alternatives.
You can use the rlogin command to establish a remote login session on another system. The
syntax for the rlogin command is:

23
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
$ rlogin hostname or ip address

The following example shows you how to log in remotely to the host2 system as another
user, user2:
$ rlogin -l user2 host2
Password:
Last login: Mon Mar 6 16:36:35 from host2
Sun Microsystems Inc. SunOS 5.9 Generic February 2000
... (output truncated)
$ pwd
/export/home/user2
$ uname -n
host2
$ exit
Connection to host2 closed.

For getting ip address : If you enter the command “ifconfig” in the terminal, all information
will be displayed. You can also use the commands “ip addr” or “ip a”. Confirm with [Enter]

Telnet command:-
Telnet :- Telnet is an old network protocol that is used to connect to remote systems over a
TCP/IP network. It connects to servers and network equipment over port 23. Let’s take a
look at Telnet command usage.
In Linux, the telnet command is used to establish a simple text-based communication
with another device or server over the Telnet protocol. However, it's important to note that
Telnet is generally considered insecure because it transmits data, including passwords, in
plain text.
Syntax:-telnet [options] [host [port]]
options: These are optional command-line options you can use with the telnet command.
host: This is the hostname or IP address of the device you want to connect to.
port: This is the port number to connect to. The default Telnet port is 23.
For example, if you want to connect to a Telnet server with the IP address "192.168.1.100"
on port 23, you would use the following command:
$ Telnet 192.168.1.100 23
To exit the telnet command, execute the logout command.
$ logout
ftp command:-
FTP:- FTP (File Transfer Protocol) is a network protocol used for transferring files from one
computer system to another. Even though the safety of FTP tends to spark a lot of discussion,
it is still an effective method of transferring files within a secure network.
In Linux, the ftp command is used to interact with remote servers using the FTP (File
Transfer Protocol) for transferring files between your local machine and the remote server.
Syntax:-telnet [options] [host [port]]
For example, if you want to connect to an FTP server with the hostname "ftp.example.com",
you would use the following command:
24
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
$ ftp ftp.example.com
After connecting, you can start using FTP commands to interact with the remote server.
To exit the FTP command, execute the logout command.
$ logout

Apr command :-
The Address Resolution Protocol (ARP) command is used to map IP addresses to
MAC addresses on a local network. The ARP command allows you to manage and
manipulate ARP cache entries on a Linux system. The ARP cache is a table that stores the
IP-to-MAC address mappings for devices on the same network segment.
What is MAC network address?
A MAC (Media Access Control) address, sometimes referred to as a hardware or physical
address, is a unique, 12-character alphanumeric attribute that is used to identify individual
electronic devices on a network. An example of a MAC address is: 00-B0-D0-63-C2-26.
What is IP address?
An Internet Protocol (IP) address is a unique numerical identifier for every device or network
that connects to the internet. Typically assigned by an internet service provider (ISP), an IP
address is an online device address used for communicating across the internet
The basic syntax of the ARP command in Linux is:
$ arp [options] [hostname]
Display ARP Cache: To view the current ARP cache entries, you can simply run the arp
command without any options:
$ arp
Add Static ARP Entry: You can manually add a static ARP entry to the cache using the -s
option:
$ sudo arp -s <IP_address><MAC_address>
For example:
$ sudo arp -s 192.168.1.100 00:11:22:33:44:55
Delete ARP Entry: To remove an ARP cache entry, use the -d option:
$ sudo arp -d <IP_address>
For example:
$ sudo arp -d 192.168.1.100
Flush ARP Cache: You can flush the entire ARP cache using the -a option:
$ sudo arp -a -d

25
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
EX 7:- Study and practice on shells /shell programming with relevant programming
constructs, syntax, usage and applications.

Whatisashell?

A shell in Linux is a command-line interface that allows users to interact with the operating
system by typing text commands. It serves as an intermediary between the user and the OS,
executing commands and displaying their results. Popular Linux shells include Bash, which is
the default on many distributions. Users can navigate the file system, launch programs, manage
files, and automate tasks through shell scripting. Shell scripting allows users to create scripts
to execute sequences of commands efficiently.

Types of shell :

Bash (Bourne Again SHell): Bash is the default shell for many Linux distributions. It is a
powerful and versatile shell that provides a wide range of features, including command-line
editing, history, tab completion, and scripting capabilities. It is based on the original Unix sh
(Bourne Shell) but with additional improvements.

sh (Bourne Shell): The original Unix shell that served as the foundation for many modern
shells. It is a simple shell with limited features compared to more recent shells like Bash.

zsh (Z Shell): Zsh is an extended version of Bash with additional features and
improvements, such as better auto-completion, spelling correction, and more customization
options.

csh (C Shell): The C Shell is another Unix shell that provides a syntax similar to the C
programming language. It offers interactive features like history and command-line editing.

tcsh (TENEX C Shell): An enhanced version of csh, offering improvements like better
command-line editing and command-line completion.

ksh (Korn Shell): The Korn Shell is another powerful shell with advanced scripting
capabilities and improved interactive features.

Whatisshellscripting?
Shell scripting is the process of writing and executing small programs (scripts) in a shell
(e.g., Bash) to automate tasks, execute commands, and control the operating system. Scripts
can combine multiple commands, use variables, and include control structures like loops and
conditionals for decision-making. Shell scripting is commonly used for automation, file
management, text processing, and system configuration on Unix-like operating systems like
Linux.
Creating a shell program
1.Using‘gedit’
26
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
One method of creating a “.sh” file is by using the edit command. You can directly create
and open a “.sh”filebyspecifying thenameofthefileasshownbelow,oryou
cansimplyusetheeditcommandand savethefile andnameitlater.

Youmustbecarefulwhilenamingyourfilebecauseifyouwritethenameofanalreadyexistingfilewit
hthe command,itwillopentheexistingfileinsteadofcreatingone.

2.Usingnanoeditor
Another method to create a “.sh” file is by using the nano editor in Linux-based operating
systems. It workssimilar to the gedit command where you specify the name of the file you
want to create next to the command

Similar to the gedit command, even the nano command will open the existing file
instead of creating a newoneifyouenterthe nameofanalreadyexistingfile.

1.UsingVieditor
We all know that the Vi editor is a really powerful editor for text manipulation, but not that
easy for textcreation,meaning it will be even harder to write shellprograms in it.None the
less, to create a “.sh” file using the ‘vi’command,specify the name of the file after the Vi
command as shown below:

Even the Vi editor will open the existing file if you enter the name of an already existing file.

PRINTING“HELLOWORLD”
To do so, write the following piece of code in your “.sh”file:

The above code includes just 2 lines (although it is technically one), the first line must be
written in all the shell programs, it simply specifies the shell we are using, in this case, it is
the bashshell.
OK, now that we have written and saved our code, how do we execute it? Well, we simply
type the command sh followed by the name of the file you save it in as follows:

27
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

sh<filename>.sh

We just printed“Hello ”

WRITING COMMENTS IN THE SHELLPROGRAMS


Printing using the echo command
As we have seen, the echo command is used to print out a specified message in the terminal,
here is an example:

The shell program above will print out the following output:

VARIABLES IN SHELL PROGRAMMING


In shell scripting and programming, variables are used to store data and values that can be
accessed and manipulated throughout the script. Variables allow you to use and modify data
dynamically, making your scripts more flexible and powerful.
To assign a variable simply follow the syntax shown below:
<varianlename>=<value>
And when you take up the name of this variable in any other parts of your program, be sure
to use the dollar sign before it
For example, in the program shown below the value of x is 10 and it is later printed using the
echo command(note the dollar sign before ‘x’):

28
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
You can even print some text before the number to give a better understanding of the output
as shown:

We can also create string variables in the same way:

We can create many variables like float, integers, strings and so many more in a similar
fashion.
READING INPUT FROM THE USER
We can read the input from the user by using the keyword “read” followed by the variable
you want to assign it to. For example the statement “read x” will read the user’s input and
store it in the variable “x”.

The shell program shown above will read the number entered by the user into the variable x
and then print it out as shown:

EXPRESSIONS IN SHELL PROGRAMMING


Now that we have learned how to deal with variables and how to read the input from users, let
us now understand how expressions work in shell programming. Here they are not as simple
as writing “2+3”,instead,youhave tomakeuse ofthe keyword“`expr”
29
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
You can even save an expression in a variable and access it later as shown:

Similarly,you can even operateon variables as shown below:

And upon running the above code, we get the following output:

OPERATORS IN SHELL PROGRAMMING:

When we are using expressions, we obviously have some operators to operate on. Operators
are of 3 types, arithmetic and relational, and logical, let us look at each of them:
The arithmetic operators are:
1. Addition(+)
2. Subtraction(-)
3. Division(/)
4. Multiplication(\*)

30
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
As you can see everything is in traditional style except for the multiplication operator, let us
look at one example of it to clarify:

The shell program shown above will print the following output:

The relational operators are:


1.Greaterthan(-gt)
2.Lessthan(-lt)
3.greaterthanorequalto(-ge)
4.Lessthanor equalto(-le)
5.Equalto(-eq)
6.Not equalto (-ne)
The logical operators are:
1.Logicaland(&&)
2.Logicalor(||)
3.Not equalto(!)
We will look at examples of these when using loops in shell programming.
“IF-ELSE” STATEMENT IN SHELL PROGRAMMING
Just like every other programming language, shell programming also had lupus and if-else
statements. Let us first look at the syntax of the if-else statements:
1. “if … then” statementIf<condition>;
Then

<arguments>Fi

31
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

output:

2.“if…then…else”statement
If <condition>Then
<arguments>Else
<arguments>Fi

32
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

The above program will give the following output:

2. “if…then…elseif…then…else”statement
If <condition>Then
<arguments>Elseif <condition>Then
<arguments>Else
<arguments>Fi

Upon executing the program shown above, we get the following output:

3. Nested if
We can also nest one if loop in side another if loop,to further narrow own the condition, the
following is a really beautiful example that illustrated if loops using all of the information we
33
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
learned till now like environment variables, logical operators, nestedif, else, comments and
more:

Upon executing the program shown above, we get the following output:

SWITCH CASE IN SHELL PROGRAMMING


In shell programming, we can use multiple if-else statements, but this is not the best solution
when all of the branches depend on the value of a single variable.
In such cases, we use “case”. In shell programming Just like if-else statements, we have
switch-case statements. Before we see an example, let us look at how it works.
The case statement is given an expression to evaluate and several different statements to
execute based on the value of the expression. The program check search case against the
value of the expression until a match is found, if it all a match is not found, it simply exits
without performing any action.
The following is the syntax followed while writing case statements:
case word in pattern1)
Statement(s) to be executed if pattern1 matches
;;
pattern2)
Statement(s) to be executed if pattern 2 matches
;;
pattern3)
Statement(s)to be executed if pattern 3 matches
;;
*)
34
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Default condition to be executed
;;
esac

Now, let us look at an example of the case state mentin action:


The output of the above-shown shell program will be:

LOOP SIN SHELL PROGRAMMING


Just like every other programming language, shell programming also has loops, namely for
loop, while loop, and do-while loop. Before we look at some examples of each let us look at
the difference between while loop and do while loop.
The while loop checks the condition first and executes a set of commands while it is true,

and exits when false. The do-while loop on the other hand first executes the set of arguments
and only then checks the condition. This means that the minimum number of times you can
execute a do-while loop is once. Let us now look at one example for each.
Forloop:

The output of the above-shown shell program will be:

35
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Whileloop:

The output of the above-shown shell program will be:

Do while loop:

The output of the above-shown shell program will be:

36
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Ex-8 :- Study and practice on awk with relevant commands, syntax ,usage, application
Awk is a scripting language used for manipulating data and generating reports. The awk
command programming language requires no compiling and allows the user to use variables,
numeric functions, string functions, and logical operators.

WHAT CAN WE DO WITH AWK?

1. AWK Operations:
(a) Scans a file line by line
(b) Splits each input line into fields
(c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines

4. Useful For:
(a) Transform data files
(b) Produce formatted reports

3. Programming Constructs:
(a) Format output lines
(b) Arithmetic and string operations
(c) Conditionals and loops

Syntax:awk 'pattern { action }' file

➢ patternis a condition that specifies which lines of the input file should be processed.
➢ action is the set of commands to be executed on the lines that match the pattern.
➢ file is the name of the input file you want to process.

Example:
Consider the following text file as the input file for all cases below:
$cat > employee.txt
O/p:
ajay manager account 45000
sunil clerk account 25000
varun manager sales 50000
amit manager account 47000
tarun peon sales 15000
deepak clerk sales 23000
sunil peon sales 13000
satvik director purchase 80000

1. Default behavior of Awk: By default Awk prints every line of data from the specified
37
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
file.
$ awk '{print}' employee.txt

Output:
ajay manager account 45000
sunil clerk account 25000
varun manager sales 50000
amit manager account 47000
tarun peon sales 15000
deepak clerk sales 23000
sunil peon sales 13000
satvik director purchase 80000
In the above example, no pattern is given. So the actions are applicable to all the lines.
Action print without any argument prints the whole line by default, so it prints all the lines of
the file without failure.

2. Print the lines which match the given pattern.


$ awk '/manager/ {print}' employee.txt

Output:
ajay manager account 45000
varun manager sales 50000
amit manager account 47000
In the above example, the awk command prints all the line which matches with the
‘manager’.

3. Splitting a Line Into Fields : For each record i.e line, the awk command splits the record
delimited by whitespace character by default and stores it in the $n variables. If the line has 4
words, it will be stored in $1, $2, $3 and $4 respectively. Also, $0 represents the whole line.
$ awk '{print $1,$4}' employee.txt

Output:

ajay 45000
sunil 25000
varun 50000
amit 47000
tarun 15000
deepak 23000
sunil 13000
satvik 80000
In the above example, $1 and $4 represents Name and Salary fields respectively.

38
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Ex 9 :- Study and practice on regular commands and the grep family with relevant
commands, syntax, usage, applications

Regular Expression provides an ability to match a “string of text” in a very flexible and
concise manner. A “string of text” can be further defined as a single character, word,
sentence or particular pattern of characters.
Like the shell’s wild–cards which match similar filenames with a single expression, grep
uses an expression of a different sort to match a group of similar patterns.

[ ]: Matches any one of a set characters


[ ] with hyphen: Matches any one of a range characters
^: The pattern following it must occur at the beginning of each line
^ with [ ] : The pattern must not contain any character in the set specified
$: The pattern preceding it must occur at the end of each line

Examples :-

(a) [ ] : Matches any one of a set characters


$grep “New[abc]” filename
It specifies the search pattern as :
Newa , Newb or Newc
$grep “[aA]g[ar][ar]wal” filename
It specifies the search pattern as
Agarwal , Agaawal , Agrawal , Agrrwal
agarwal , agaawal , agrawal , agrrwal

(b) Use [ ] with hyphen: Matches any one of a range characters


$grep “New[a-e]” filename
It specifies the search pattern as
Newa , Newb or Newc , Newd, Newe
$grep “New[0-9][a-z]” filename
It specifies the search pattern as: New followed by a number and then an alphabet.
New0d, New4f etc

(c ) Use ^: The pattern following it must occur at the beginning of each line
$grep “^san” filename
Search lines beginning with san. It specifies the search pattern as
sanjeev ,sanjay, sanrit , sanchit , sandeep etc.
$ls –l |grep “^d”
Display list of directories only
$ls –l |grep “^-”
Display list of regular files only

(d) Use ^ with [ ]: The pattern must not contain any character in the set specified
$grep “New[^a-c]” filename
39
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
It specifies the pattern containing the word “New” followed by any character other than an
‘a’,’b’, or ‘c’
$grep “^[^a-z A-Z]” filename
Search lines beginning with an non-alphabetic character

(e) Use $: The pattern preceding it must occur at the end of each line
$ grep "vedik$" file.txt

40
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Ex 10 :- Study and practice on compilation process of c program

The compilation is the process of converting the source code of the C language into machine
code. As C is a mid-level language, it needs a compiler to convert it into an executable code
so that the program can be run on our machine.
The C program goes through the following phases during compilation:

Compilation Process in C
How do we compile and run a C program?
We first need a compiler and a code editor to compile and run a C Program. The below
example is of an Ubuntu machine with GCC compiler.

Step 1: Creating a C Source File


We first create a C program using an editor and save the file as filename.c
$ vi filename.c
We can write a simple hello world program and save it.

Step 2: Compiling using GCC compiler


We use the following command in the terminal for compiling our filename.c source file
$ gcc filename.c –o filename
We can pass many instructions to the GCC compiler to different tasks such as:
➢ The option -Wall enables all compiler’s warning messages. This option is recommended
to generate better code.
➢ The option -o is used to specify the output file name. If we do not use this option, then an
output file with the name a.out is generated.
If there are no errors in our C program, the executable file of the C program will be
generated.

Step 3: Executing the program


After compilation executable is generated and we run the generated executable using the
41
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
below command.
$ ./filename
The program will be executed and the output will be shown in the terminal.

What goes inside the compilation process?


A compiler converts a C program into an executable. There are four phases for a C program
to become an executable:
⚫ Pre-processing
⚫ Compilation
⚫ Assembly
⚫ Linking

Let us one by one see what these intermediate files contain.

1. Pre-processing
This is the first phase through which source code is passed. This phase includes:
➢ Removal of Comments
➢ Expansion of Macros
➢ Expansion of the included files.
➢ Conditional compilation
The preprocessed output is stored in the filename.I Let’s see what’s inside filename.i:
using $vi filename.i
In the above output, the source file is filled with lots and lots of info, but in the end, our code
is preserved.
➢ printf contains now a + b rather than add(a, b) that’s because macros have expanded.
➢ Comments are stripped off.
➢ #include<stdio.h> is missing instead we see lots of code. So header files have been
expanded and included in our source file.
➢ Conditional compilation provides a way of including or omitting selected lines of source
code depending on the values of literals specified by the DEFINE directive.

2. Compiling
The next step is to compile filename.i and produce an; intermediate compiled output
file filename.s. This file is in assembly-level instructions.
3. Assembling
42
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
In this phase the filename.s is taken as input and turned into filename.o by the assembler.
This file contains machine-level instructions. At this phase, only existing code is converted
into machine language, and the function calls like printf() are not resolved. Let’s view this
file using $vi filename.o

Binary Code
4. Linking
This is the final phase in which all the linking of function calls with their definitions is done.
Linker knows where all these functions are implemented. Linker does some extra work also,
it adds some extra code to our program which is required when the program starts and ends.
For example, there is a code that is required for setting up the environment like passing
command line arguments. This task can be easily verified by using $size
filename.o and $size filename. Through these commands, we know how the output file
increases from an object file to an executable file. This is because of the extra code that
Linker adds to our program.

43
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Basic Viva Questions and Answers

1. What is Linux?
o Linux is an open-source, Unix-like operating system based on the Linux kernel,
developed by Linus Torvalds in 1991.
2. What is an operating system (OS)?
o An OS is system software that manages hardware and software resources and
provides services for computer programs.
3. What is the difference between Linux and Unix?
o Unix is a proprietary operating system developed in the 1970s, while Linux is
open-source and Unix-like, offering similar functionality but with free and
collaborative development.
4. What are the main components of the Linux operating system?
o The Kernel, System Libraries, and System Utilities.
5. What is the kernel in Linux?
o The kernel is the core part of Linux, responsible for managing hardware
resources and providing services to applications.
6. What is a shell in Linux?
o A shell is a command-line interface that allows users to interact with the
operating system by executing commands.
7. Explain the difference between kernel mode and user mode.
o Kernel mode has unrestricted access to system resources, while user mode is
restricted to prevent accidental system damage.
8. What does open-source mean?
o Open-source refers to software with publicly available source code, allowing
users to modify and distribute it freely.
9. What is multi-user capability in Linux?
o It means multiple users can access system resources simultaneously without
interfering with each other.
10.What is the difference between a process and a program?
o A program is a set of instructions, while a process is a running instance of a
program.

44
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 1: File System and File Handling Commands

1. What is a file system in Linux?


o A file system is a method for storing and organizing files on storage devices.
2. Name the three types of files in Linux.
o Regular files, Directories, and Special files.
3. What command displays the current working directory?
o pwd
4. How do you create a new directory?
o mkdir<directory_name>
5. Which command deletes a directory?
o rmdir<directory_name>
6. What is the purpose of the ls command?
o Lists the contents of a directory.
7. How do you change to a different directory?
o cd <directory_name>
8. What command creates an empty file?
o touch <file_name>
9. How can you display the contents of a file?
o cat <file_name>
10.Which command removes a file?
o rm<file_name>
11.How do you copy a file?
o cp<source_file><destination_file>
12.Which command moves or renames a file?
o mv <source_file><destination>
13.Explain the root directory in Linux.
o The root directory (/) is the top-most directory in the file system hierarchy.
14.What is the difference between rm and rmdir?
o rm deletes files, while rmdir deletes empty directories.
15.What is the use of the file command?
o It determines the type of a file.

45
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College
Experiment 2: VI Editor

1. What is the VI editor?


o It is a text editor available in almost all Linux distributions.
2. Name two modes of the VI editor.
o Command mode and Insert mode.
3. How do you switch from command mode to insert mode?
o Press i.
4. What command saves changes and exits VI?
o :wq
5. How do you quit VI without saving changes?
o :q!
6. What command deletes a line in VI?
o dd
7. Which command moves the cursor up?
o k
8. How do you undo the last change?
o u
9. Explain the use of the x command.
o Deletes the character under the cursor.
10.How do you replace a character in VI?
o r <new_character>
11.What does the o command do?
o Opens a new line below the current line.
12.How do you move to the end of a line?
o Press $.
13.What is VIM?
o An improved version of the VI editor.
14.Explain the dw command.
o Deletes a word.
15.What is the difference between A and a?
o A appends at the end of the line, a after the cursor.

46
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 3: I/O Redirection

1. What is I/O redirection?


o Changing the input/output source of a command.
2. Which symbol is used for input redirection?
o <
3. How do you redirect output to a file?
o command >file_name
4. Explain >> in output redirection.
o Appends output to an existing file.
5. What is the purpose of 2>?
o Redirects error output.
6. What are standard input, output, and error streams?
o stdin (0), stdout (1), stderr (2).
7. Which command concatenates and displays file content?
o cat
8. How do you suppress error messages?
o command 2> /dev/null
9. Explain the use of pipes (|).
o Connects the output of one command to another.
10.What does cat < file.txt do?
o Takes file.txt as input and displays content.
11.What is /dev/null?
o A special file that discards all data written to it.
12.How do you combine stdout and stderr?
o command > output.txt 2>&1
13.What is the difference between > and >>?
o > overwrites, >> appends.
14.Explain echo Hello > file.txt.
o Writes "Hello" into file.txt.
15.What command shows only error messages?
o command 2>&1 >/dev/null

47
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 4: Filters

1. What is a filter in Linux?


o A filter is a command that processes text data and transforms it into output.
2. Name any two filter commands.
o grep and sort
3. What does the grep command do?
o Searches for a pattern in files.
4. How do you perform a case-insensitive search using grep?
o grep -i<pattern><file>
5. What is the purpose of the sort command?
o Sorts the lines of a file.
6. Explain numeric sorting in sort.
o Use sort -n for numeric sorting.
7. Which command prints the first 10 lines of a file?
o head <file>
8. What does the tail command do?
o Displays the last 10 lines of a file.
9. Explain the tac command.
o Displays file content in reverse order.
10.What does the uniq command do?
o Filters out duplicate lines.
11.Which command counts words, lines, and characters?
o wc
12.What is the purpose of the sed command?
o Edits text using patterns without changing the file.
13.How do you count lines in a file using wc?
o wc -l <file>
14.Explain grep -v command.
o Displays lines that do not match the pattern.
15.How can you display unique sorted words using sort and uniq?
o sort <file> | uniq

48
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 5: Backup Commands

1. Why are backups important?


o They protect against data loss and enable recovery.
2. What does the tar command do?
o Creates archives of files and directories.
3. Which option compresses with gzip in tar?
o -z
4. How do you extract a tar archive?
o tar -xvf archive.tar
5. Explain the difference between gzip and bzip2.
o gzip is faster, bzip2 compresses more.
6. What command lists archive contents?
o tar -tvf archive.tar
7. What is tar -cvf used for?
o Creates an archive.
8. How do you append to an archive?
o tar -rvf archive.tar file
9. Explain tar -czvf.
o Creates a gzip compressed archive.
10.What does tar -xzvf do?
o Extracts a gzip archive.
11.What is the purpose of tar -u?
o Updates files if they are newer.
12.Explain the -f option in tar.
o Specifies the archive filename.
13.How do you create a bzip2 archive?
o tar -cjvf archive.tar.bz2 files
14.How can you view the manual for tar?
o man tar
15.What is an archive in Linux?
o A collection of files stored as one.

49
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 6: Internet Commands

1. What does the ping command do?


o Checks connectivity to a host.
2. How do you find your IP address?
o ifconfig or ip a
3. What is ftp used for?
o Transfers files between systems.
4. Explain the telnet command.
o Connects to remote systems.
5. What is finger used for?
o Displays user information.
6. Which command shows the ARP table?
o arp
7. What does rlogin do?
o Allows remote login.
8. Explain wget.
o Downloads files from the internet.
9. What is the default port for telnet?
o Port 23.
10.How do you exit ftp?
o Type bye or quit.
11.Explain curl.
o Transfers data from URLs.
12.What is a MAC address?
o A unique identifier for network devices.
13.How do you clear the ARP cache?
o arp -a -d
14.Explain the use of scp.
o Securely copies files between systems.
15.How do you show routing information?
o netstat -r

50
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 7: Shell Programming

1. What is a shell in Linux?


o A command-line interface for interacting with the OS.
2. Name the default shell in most Linux systems.
o Bash.
3. What is shell scripting?
o Writing scripts to automate tasks.
4. Which command prints output in shell scripts?
o echo
5. How do you execute a script?
o sh script.sh
6. What symbol denotes comments in shell scripts?
o #
7. Explain variables in shell scripting.
o Used to store data.
8. How do you read user input in a script?
o read variable_name
9. What is expr used for?
o Evaluates expressions.
10.How do you write an if statement?
o if [ condition ]; then commands; fi
11.What is a loop in scripting?
o Repeats a set of commands.
12.Name two types of loops in shell scripting.
o for loop and while loop.
13.How do you create a for loop?
o for var in list; do commands; done
14.What is the difference between while and do-while?
o while checks first, do-while runs at least once.
15.How do you define a function?
o function_name() { commands; }

51
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 8: AWK

1. What is AWK?
o A text processing tool.
2. How do you print every line using AWK?
o awk '{print}' file.txt
3. Explain $1 in AWK.
o Refers to the first field.
4. What does awk '/pattern/ {print}' do?
o Prints lines matching the pattern.
5. How do you print specific columns?
o awk '{print $1, $2}' file.txt
6. Explain the use of BEGIN.
o Executes actions before processing.
7. What is END in AWK?
o Executes actions after processing.
8. How do you calculate sums with AWK?
o awk '{sum+=$1} END {print sum}' file.txt
9. Explain FS in AWK.
o Sets the field separator.
10.What is NR in AWK?
o Current record number.
11.How do you format output in AWK?
o Use printf.
12.Explain pattern matching in AWK.
o Uses regular expressions.
13.How do you filter data with conditions?
o awk '$1 > 100 {print}' file.txt
14.What is OFS in AWK?
o Sets the output field separator.
15.How do you print line numbers?
o awk '{print NR, $0}' file.txt

52
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 9: Regular Expressions

1. What is a regular expression?


o A pattern for matching text.
2. What does ^ mean?
o Matches the beginning of a line.
3. How do you match a digit?
o [0-9]
4. Explain grep "abc$".
o Matches lines ending with "abc".
5. What does [^a-z] do?
o Matches non-lowercase letters.
6. Explain the use of * in regex.
o Matches zero or more of the preceding.
7. What is the .character in regex?
o Matches any single character.
8. How do you match abc or def?
o (abc|def)
9. Explain [a-z A-Z].
o Matches any letter.
10.What does grep "\bword\b" do?
o Matches the word "word".
11.How do you display only directories with ls?
o ls -l | grep "^d"
12.Explain the difference between .and*.
o .matches one, * matches many.
13.What is a wildcard?
o A character for pattern matching.
14.How do you escape special characters?
o Use \.
15.What does sed 's/old/new/' do?
o Substitutes "old" with "new".

53
R.BHANU SANKAR
Sanketika Vidya Parishad Engineering College

Experiment 10: Compilation Process

1. What is compilation?
o Converting source code to machine code.
2. Name the first phase of compilation.
o Preprocessing.
3. What command compiles C programs?
o gcc
4. Explain the -o option in gcc.
o Specifies output filename.
5. What is a.out?
o Default executable.
6. How do you link object files?
o gcc file1.o file2.o
7. What happens in the assembly phase?
o Converts to assembly code.
8. Explain the role of a linker.
o Resolves function calls.
9. What does gcc -Wall do?
o Enables all warnings.
10.How do you run an executable?
o ./filename
11.Explain the use of size command.
o Displays section sizes of a binary.
12.What is filename.i?
o Preprocessed output.
13.How do you generate an object file?
o gcc -c file.c
14.What is filename.s?
o Assembly code.
15.What does filename.o contain?
o Machine-level instructions.

54
R.BHANU SANKAR

You might also like