0% found this document useful (0 votes)
20 views61 pages

LINUX Sem5 RGPV

basics of linux
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)
20 views61 pages

LINUX Sem5 RGPV

basics of linux
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/ 61

Department of Computer Science & Information

Technology

II Year,IV Semester(Batch 2020-2024)


Lab Record Submission
of

Linux lab
Subject Code – CSIT-505

Submitted to: Submitted by:


Prof. Nidhi Nigam Isha Choudhary
0827CI221065
INDEX

S.No Name of Experiment Date of Page Date of Faculty


. Experiment no. Submission Sign

01 Introduction of OS, function 5/9/2024 2-5 14/10/2024


services of OS.Need for linux,
History of linux and
different services of linux

02 Study of basic user and shell 12/9/2024 6-16 14/10/2024


command

03 Study of linux architecture with 19/9/2024 17-23 14/10/2024


different types of kernel shell

04 Understanding linux file system 26/9/2024 24-29 14/10/2024

05 Study of linux editor with their 7/10/2024 30-32 21/10/2024


command specification

06 Create a file called wlcc.txt with 10/10/2024 33 21/10/2024


some line and display how many
lines words and characters are
present in the file

07 Append ten more simple line to 14/10/2024 34 21/10/2024


the file and display

08 Study and use of commands and 21/10/2024 35-37 21/10/2024


for changing file permission

Isha Choudhary 0827CI221065

1
Experiment No.1

Introduction of operating System:

An operating system (OS) is essential for managing and facilitating interactions between a computer's
hardware and software. It provides a structured environment for executing programs and handling tasks
like file management. In the context of a file experiment, the OS plays a crucial role by allowing users
to create, modify, and delete files, and by organizing these files into directories or folders.

It also manages file permissions, which control access rights and ensure that only authorized users can
perform certain actions on files. Additionally, the OS employs a file system, such as NTFS, FAT32, or
ext4, to systematically organize and store files on storage devices. During your experiment, you will
observe how the OS efficiently handles these file operations and maintains an organized structure for
data management.

Function of Operating System

●​ Memory Management- An operating system manages the allocation and deallocation of


memory to various processes and ensures that the other process does not consume the memory
allocated to one process.

●​ Processor Management- An operating system manages the processor’s work by allocating


various jobs to it and ensuring that each process receives enough time from the processor to
function properly.Keeps track of the status of processes.

●​ Booting the Computer- The process of starting or restarting the computer is known as
booting. If the computer is switched off completely and if turned on then it is called cold
booting. Warm booting is a process of using the operating system to restart the computer.

●​ Security- The operating system uses password protection to protect user data and similar
other techniques. it also prevents unauthorized access to programs and user data.

Isha Choudhary 0827CI221065

2
●​ User Interface or Command Interpreter- The user interacts with the computer system
through the operating system. Hence OS acts as an interface between the user and the
computer hardware. This user interface is offered through a set of commands or a graphical
user interface (GUI).

●​ Network Management- Network Communication: Think of them as traffic cops for your
internet traffic. Operating systems help computers talk to each other and the internet. Settings
and Monitoring: Think of them as the settings and security guard for your internet connection.

Services of Operating System:

●​ User Interface: Almost all operating systems have a user interface (UI). This interface can take
several forms. One is a command-line interface(CLI), which uses text commands and a method
for entering them ( a keyboard for typing in commands in a specific format with specific
options).

●​ Program Execution: The Operating System is responsible for the execution of all types of
programs whether it be user programs or system programs.

●​ Handling Input/Output Operations: The Operating System is responsible for handling all
sorts of inputs, i.e., from the keyboard, mouse, desktop, etc. The Operating System does all
interfacing most appropriately regarding all kinds of Inputs and Outputs.

●​ Manipulation of File System: The Operating System is responsible for making decisions
regarding the storage of all types of data or files.

●​ Resource Allocation: The Operating System ensures the proper use of all the resources
available by deciding which resource to be used by whom for how much time.

●​ Accounting: The Operating System tracks an account of all the functionalities taking place in
the computer system at a time.

●​ System Services: The operating system provides various system services, such as printing, time
and date management, and event logging.

●​ Error Detection: The operating system needs to be detecting and correcting errors
constantly..For each type of error, the operating system should take the appropriate action to
ensure correct and consistent computing.

Isha Choudhary 0827CI221065

3
Need for linux operating system:

●​ Open Source: Linux is open source, meaning its source code is freely available for anyone to
view, modify, and distribute. This fosters innovation and customization.

●​ Stability and Reliability: Known for its stability and reliability, Linux is often used in
environments where uptime is critical, such as servers and embedded systems.

●​ Security: Linux is designed with robust security features and has a strong community of
developers who quickly address vulnerabilities and provide patches.

●​ Cost-Effective: Linux is free to use, reducing costs associated with licensing fees compared
to proprietary operating systems.

●​ Flexibility and Customization: Linux can be tailored to suit specific needs, from lightweight
distributions for older hardware to powerful configurations for advanced users and servers.

●​ Performance: Linux typically has a smaller footprint and can be optimized for performance,
making it suitable for a wide range of hardware.

●​ Community Support: A vibrant community of users and developers provides extensive


support and resources, including forums, documentation, and user guides.

History Of linux Operating System:

Linux originated in 1991 when Linus Torvalds, a Finnish student, released the first version of the
Linux kernel as a free and open-source alternative to proprietary operating systems. Initially
developed as a personal project, Linux quickly garnered support from a global community of
developers.

By adhering to the principles of open source, it allowed continuous improvements and adaptations.
Over the years, Linux evolved into a robust and versatile operating system used across various
domains, from personal computers to servers and embedded systems.

Its development has been driven by contributions from both individual programmers and large
organizations,leading to a diverse ecosystem of distributions tailored for different needs.

Isha Choudhary 0827CI221065

4
Different Services and Application Of Linux Operating system :

●​ Web Servers: Powers popular web servers like Apache and Nginx.

●​ Database Management: Supports database systems such as MySQL, PostgreSQL, and


MongoDB.

●​ File Servers: Provides file sharing services with tools like Samba and NFS.

●​ Development Environment: Used by developers for programming with support for various
programming languages and development tools.

●​ Security: Provides strong security features and tools, including SELinux and AppArmor.

●​ Virtualization: Supports virtualization platforms like KVM, Docker, and VirtualBox.

●​ Desktop Environments: Offers various desktop environments like GNOME, KDE, and
XFCE for user interfaces.

Isha Choudhary 0827CI221065

5
Experiment No.2

Aim : To get the function of command of linux command

1.ls :
Description: list directory content.
Syntax: ls

2.ls -l :
Description: list directory contents with detail
Syntax: ls -l

3.cat :
Description: Concatenate files and print on the standard output
Syntax: cat

Isha Choudhary 0827CI221065

6
4..Whoami :-
Description: The whoami command in Linux displays the username of the currently logged-in user.
Syntax: Whoami

5.Whatis:-
Description: display one-line manual page descriptions
Syntax: Whatis

6.Date :-
Description: date command is used to display the system date and time. date command is also used to
set date and time of the system.
Syntax: Date

7.Man :-
Description: an interface to the system reference manuals
Syntax: Man

Isha Choudhary 0827CI221065

7
8.mkdir :-
Description: Create a new directory.
Syntax: mkdir folder name

9.cd :-
Description: Change directory.
Syntax: cd folder name

10.rmdir :-
Description: remove empty directories
Syntax: rmdir folder name

Isha Choudhary 0827CI221065

8
11.Vi :-
Description: Vi IMproved, a programmer's text editor
Syntax: Vi

12.MV :-
Description: move and rename files.
Syntax:MV currentfolder destinationfolder

Isha Choudhary 0827CI221065

9
13.CP :-
Description: copy files and directories
Syntax:CP

14.Grep :-
Description: print lines that match patterns
Syntax:Grep

15.Su :-
Description: run a command with substitute user and group ID
Syntax:Su

16.Sudo :-
Description: execute a command as another user

Isha Choudhary 0827CI221065

10
Syntax:Sudo

17.nano :-
Description: Nano's ANOther editor, inspired by Pico
Syntax:nano

18.find :-
Description: search for files in a directory hierarchy
Syntax: find -name file name

19.ps :-
Description: report a snapshot of the current processes.
Syntax:ps

Isha Choudhary 0827CI221065

11
21.Df :-
Description: report file system disk space usage.
Syntax:Df

22.Chmode :-
Description: change file mode bits
Syntax:Chmode +r file name

23.Touch :-
Description: Create File
Syntax:Touch filename

Isha Choudhary 0827CI221065

12
24.Pwd :-
Description: Print current working directory.
Syntax:Pwd

25.Cal :-
Description: to show the calendar.
Syntax:Cal

26.echo:-
Description: used to print something in the terminal
Syntax:echo text >filename

Isha Choudhary 0827CI221065

13
27.uname
Description:Linux command to get basic information about the OS
Syntax:uname -a

28.sort
Description:Linux command to sort the content of a file while outputting
Syntax: sort filename

29.Ps
Description:Display active processes
Syntax: ps

Isha Choudhary 0827CI221065

14
30. Cmp
Description-Allows you to check if two files are identical
Syntax: cmp file1.txt file2.txt

31. Wc
Description:The wc (word count) command prints counts of lines, words, and bytes in a file.
Syntax: wc file name

32.Umask
Description:The umask command controls the default permissions given to newly created files.
Syntax: umask

33.Free
Description:The free command shows the total, used and free amounts of physical and swap memory
on the system. T
Syntax:Free

Isha Choudhary 0827CI221065

15
34.Uptime
Description:The uptime command shows how long the Linux system has been running since it was
last rebooted.
Syntax: uptime

35.Date :-
Description: date command is used to display the system date and time. date command is also used to
set date and time of the system.
Syntax: Date

36.Chmod :-
Description: change file mode bits
Syntax:Chmod +r filename.txt

37.find :-
Description: search for files in a directory hierarchy
Syntax:find -name filename.txt

Isha Choudhary 0827CI221065

16
Experiment No.3

Aim : Study of Linux Architecture different types of kernel and shell

A] linux Architecture

The Linux operating system's architecture mainly contains some of the components: the Kernel,
System Library, Hardware layer, System, and Shell utility.

Architecture of OS linux

1. Kernel:-
The kernel is one of the core sections of an operating system. It is responsible for each of the major
actions of the Linux OS. This operating system contains distinct types of modules and cooperates
with underlying hardware directly. The kernel facilitates required abstraction for hiding details of
low-level hardware or application programs to the system.

Isha Choudhary 0827CI221065

17
2. System Libraries:-
These libraries can be specified as some special functions. These are applied for implementing the
operating system's functionality and don't need code access rights of the modules of the kernel.

3. System Utility Programs:-


It is responsible for doing specialized level and individual activities.

4. Hardware layer:-
Linux operating system contains a hardware layer that consists of several peripheral devices like
CPU, HDD, and RAM.

5. Shell:-
It is an interface among the kernel and user. It can afford the services of the kernel. It can take
commands through the user and runs the functions of the kernel. These operating systems are
categorized into two different types, which are the graphical shells and command-line shells.

B] Types of kernel

The kernel manages the system’s resources and facilitates communication between hardware and
software components. These kernels are of different types as follows:

Types of kernel

Isha Choudhary 0827CI221065

18
1. Monolithic Kernel

It is one of the types of kernel where all operating system services operate in kernel space. It has
dependencies between system components. It has huge lines of code which is complex.

2. Micro Kernel

It is a kernel type which has a minimalist approach. It has virtual memory and thread scheduling. It is
more stable with less services in kernel space. It puts rest in user space. It is used in small os.

3. Hybrid Kernel

It is the combination of both monolithic kernel and microkernel. It has speed and design of
monolithic kernel and modularity and stability of microkernel.

4. Exo Kernel

It is the type of kernel which follows an end-to-end principle. It has as few hardware abstractions as
possible. It allocates physical resources to applications.

5. Nano Kernel

It is the type of kernel that offers hardware abstraction but without system services. Micro Kernel also
does not have system services therefore the Microkernel and Nano Kernel have become analogous.

Isha Choudhary 0827CI221065

19
C] Types of Shells

SHELL is a program which provides the interface between the user and an operating system. When
the user logs in, the OS starts a shell for the user.

Types of linux shells

1] Bash Shell

Bash, short for Bourne-Again SHell, is the most commonly used shell in Linux. It is the default shell
in most Linux distributions and is also the most powerful. Bash provides a range of features,
including command history, tab completion, and scripting.

Example − To use Bash shell, simply open the terminal and type "bash" or "bash -l" to start a new
session.

2] Tcsh Shell

Tcsh is an enhanced version of C shell (csh) that offers many advanced features designed to make
working in terminal more efficient. It includes advanced tab completion, command history, and job
control.

Example − To use Tcsh shell, first, check if it is installed on your system. If it is not, you can install it
using your package manager. Once installed, you can switch to the Tcsh shell by typing "tcsh" or
"tcsh -l" in the terminal.

Isha Choudhary 0827CI221065

20
3] Ksh Shell

Ksh, short for Korn SHell, is a powerful shell that offers many advanced features not available in
other shells. It includes advanced scripting capabilities, job control, and built-in arithmetic operations.
Ksh also provides extensive customization options, allowing users to create their own aliases and
functions.

Example − To use Ksh shell, first, check if it is installed on your system. If it is not, you can install it
using your package manager. Once installed, you can switch to the Ksh shell by typing "ksh" or "ksh
-l" in the terminal.

4] Zsh Shell

Zsh is a powerful and highly customizable shell that offers many features not available in Bash. It
includes advanced completion capabilities, spelling correction, and a powerful scripting language.
Zsh also offers extensive customization options, allowing users to create their own themes and
plugins.

Example − To use Zsh shell, first, check if it is installed on your system. If it is not, you can install it
using your package manager. Once installed, you can switch to the Zsh shell by typing "zsh" or "zsh
-l" in the terminal.

5] Fish Shell

Fish, short for Friendly Interactive SHell, is a user-friendly shell that offers many features designed to
make working in terminal more enjoyable. It includes syntax highlighting, auto-suggestions, and a
built-in help system. Fish is also highly customizable, allowing users to create their own functions
and commands.

Example − To use Fish shell, simply open the terminal and type "fish" or "fish -l" to start a new
session.

Isha Choudhary 0827CI221065

21
Difference Between Shell and Kernel

Shell Kernel

Shell allows the users to communicate with the


Kernel controls all the tasks of the system.
kernel.

It is the interface between kernel and user. It is the core of the operating system.

Its a low level program interfacing with the


It is a command line interpreter (CLI). hardware (CPU, RAM, disks) on top of which
applications are running.

Its types are – Bourne Shell, C shell, Korn Shell, Its types are – Monolithic Kernel, Micro
etc. kernel, Hybrid kernel, etc.

Isha Choudhary 0827CI221065

22
It carries out commands on a group of files by
It performs memory management.
specifying a pattern to match

Shell commands like ls, mkdir and many more can


be used to request to complete the specific It performs process management.
operation to the OS.

It is the outer layer of OS. It is the inner layer of OS.

Kernel directly interacts with the hardware by


It interacts with user and interprets to machine
accepting machine understandable language
understandable language.
from the shell.

Core component of the operating system that


Command-line interface that allows user manages system resources
interaction

Isha Choudhary 0827CI221065

23
Experiment No.4

Aim : To Study the Linux file system

A Linux file system is generally a built-in layer of a Linux operating system used to handle the data
management of the storage. It helps to arrange the file on the disk storage. It manages the file name,
file size, creation date, and much more information about a file.

If we have an unsupported file format in our file system, we can download software to deal with it.

Linux File System Structure

A file system mainly consists of 3 layers. From top to bottom:

1. Logical File System:

The Logical File System acts as the interface between the user applications and the file system itself.
It facilitates essential operations such as opening, reading, and closing files. Essentially, it serves as
the user-friendly front-end, ensuring that applications can interact with the file system in a way that
aligns with user expectations.

2. Virtual File System:

The Virtual File System (VFS) is a crucial layer that enables the concurrent operation of multiple
instances of physical file systems. It provides a standardized interface, allowing different file systems
to coexist and operate simultaneously. This layer abstracts the underlying complexities, ensuring
compatibility and cohesion between various file system implementations.

3. Physical File System:

The Physical File System is responsible for the tangible management and storage of physical memory
blocks on the disk. It handles the low-level details of storing and retrieving data, interacting directly

Isha Choudhary 0827CI221065

24
with the hardware components. This layer ensures the efficient allocation and utilization of physical
storage resources, contributing to the overall performance and reliability of the file system.

Architecture of a File System

Linux File System Hierarchy

All files on a Linux system are stored on file systems which are organized into a single inverted tree
of directories, know as a file system hierarchy.In the inverted tree, root lies at the top and the
branches of directories and subdirectories stretch below the root.

The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines the directory
structure and directory contents in Unix-like operating systems. It is maintained by the Linux
Foundation.
●​ In the FHS, all files and directories appear under the root directory /, even if they are
stored on different physical or virtual devices.
●​ Some of these directories only exist on a particular system if certain subsystems, such as
the X Window System, are installed.
●​ Most of these directories exist in all UNIX operating systems and are generally used in
much the same way; however, the descriptions here are those used specifically for the FHS
and are not considered authoritative for platforms other than Linux.
Isha Choudhary 0827CI221065

25
Figure : Linux File System Hierarchy

Here, the directories ‘/’ is the root directory which lies at the top of file system hierarchy. The ‘/’
character is also used as a directory separator in the file name, for example ‘/etc’ is a sub-directory of
‘/’ directory.

Important RHEL (Red Hat Enterprise Linux) directories

Location​ Purpose

/usr​
Installed software, shared libraries, include files, and static read-only program data. Important
subdirectories include:-
* /usr/bin: User commands.
* /usr/sbin: System administration commands.
* /usr/local: Locally customized software.

/etc​
Configuration files specific to this system.

Isha Choudhary 0827CI221065

26
/var ​
Files that dynamically change (e.g. databases, cache directories, log files, printer spooled documents,
and website content) may be found under /var.

/run​
Run-time data for processes started since the last boot. This includes process ID files and lock files,
among other things. The contents of this directory are recreated on reboot.

/home ​
Home directories where regular users store their personal data and configuration files.

/root​
Home directory for the administrative superuser, root.

/tmp
A world-writable space for temporary files. Files more than 10 days are automatically deleted from
that directory. Another temporary directory exists at /var/tmp, in which files that have not been
accessed,changed, or modified in more than 30 days are deleted automatically.

/boot​
Files needed in order to start the boot process.

/dev​
Contains special device files which are used by the system to access hardware.

Isha Choudhary 0827CI221065

27
Types of Linux File System

When we install the Linux operating system, Linux offers many file systems such as Ext, Ext2, Ext3,
Ext4, JFS, ReiserFS, XFS, btrfs, and swap.

Figure: Types of Linux File System

Let's understand each of these file systems in detail:

1. Ext, Ext2, Ext3 and Ext4 file system


The file system Ext stands for Extended File System. It was primarily developed for MINIX OS. The
Ext file system is an older version, and is no longer used due to some limitations.

Ext2 is the first Linux file system that allows managing two terabytes of data. Ext3 is developed
through Ext2; it is an upgraded version of Ext2 and contains backward compatibility. The major
drawback of Ext3 is that it does not support servers because this file system does not support file
recovery and disk snapshot.

Ext4 file system is the faster file system among all the Ext file systems. It is a very compatible option
for the SSD (solid-state drive) disks, and it is the default file system in Linux distribution.

Isha Choudhary 0827CI221065

28
2. JFS File System
JFS stands for Journaled File System, and it is developed by IBM for AIX Unix. It is an alternative to
the Ext file system. It can also be used in place of Ext4, where stability is needed with few resources.
It is a handy file system when CPU power is limited.

3. ReiserFS File System


ReiserFS is an alternative to the Ext3 file system. It has improved performance and advanced
features. In the earlier time, the ReiserFS was used as the default file system in SUSE Linux, but later
it changed some policies, so SUSE returned to Ext3. This file system dynamically supports the file
extension, but it has some drawbacks in performance.

4. XFS File System


XFS file system was considered as high-speed JFS, which is developed for parallel I/O processing.
NASA is still using this file system with its high storage server (300+ Terabyte server).

5. Btrfs File System


Btrfs stands for the B tree file system. It is used for fault tolerance, repair system, fun administration,
extensive storage configuration, and more. It is not a good suit for the production system.

6. Swap File System


The swap file system is used for memory paging in Linux operating system during the system
hibernation. A system that never goes in hibernate state is required to have swap space equal to its
RAM size.

Isha Choudhary 0827CI221065

29
Experiment No.5

Study of linux editor with their command specification

Linux text editors are software applications used to create, modify, and manipulate text files in a
Linux operating system. They are essential tools for programmers, system administrators, and anyone
working with text-based data. Linux text editors can be broadly categorized into two types:
command-line editors and graphical editors.

Key Features of Linux Text Editors

●​ Syntax Highlighting: Most editors can highlight different parts of code or markup to improve
readability.
●​ Search and Replace: Editors typically include search functionality, often with support for
regular expressions.
●​ Multiple File Support: Many editors can handle multiple files at once, either through tabs or
split views.
●​ Customization: Users can often customize key bindings, themes, and other settings to
enhance their workflow.
●​ Version Control Integration: Some editors support integration with version control systems
like Git.

Use Cases

●​ Programming: Writing and editing code in various programming languages.


●​ Configuration: Modifying configuration files for applications or the operating system.
●​ Documentation: Creating and editing text documents, markdown files, or readme files.

Isha Choudhary 0827CI221065

30
Linux text editors can be broadly categorized into two types:

1. Command-Line Text Editors

These editors run in the terminal and are often preferred for their efficiency and speed. Some popular
command-line editors include:

●​ Vi/Vim:
●​ Nano:

2. Graphical Text Editors

These editors provide a graphical user interface (GUI) and are more visually oriented. They are
generally easier for beginners and often include features like syntax highlighting, multiple tabs, and
drag-and-drop support. Some popular graphical editors include:

●​ Sublime Text:
●​ Atom:

1. Vi/Vim

Overview:

●​ Vim is a popular text editor program used on Linux and other Unix operating systems. It is an
improved and updated version of the old vi editor. While vim looks basic, it is actually a very
powerful tool for editing files efficiently, especially for programmers and developers. What
makes vim unique is that it has different “modes” for different tasks like navigating files,
editing text, and running commands.

Basic Commands:

●​ i: Enter insert mode (to edit text).


●​ Esc: Return to normal mode.
●​ :w: Save the file.
●​ :q: Quit.
●​ :wq: Save and quit.
●​ dd: Delete a line.
●​ yy: Copy a line.
●​ p: Paste copied text.

Isha Choudhary 0827CI221065

31
Nano Editor
Nano is a user-friendly and lightweight command-line text editor widely used on Unix-based systems,
known for its simple interface with on-screen keyboard shortcuts, syntax highlighting support for
programming languages, and basic editing features like search/replace, undo/redo, and multiple file
buffers, making it an accessible choice for beginners and experienced users alike.
Basic Commands:

●​ Ctrl + O: Save the file.


●​ Ctrl + X: Exit.
●​ Ctrl + K: Cut the current line.
●​ Ctrl + U: Uncut (paste) the line.
●​ Ctrl + G: Open help.

Figure:command line text editor

Isha Choudhary 0827CI221065

32
Experiment No.6

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

To create a file called wlcc.txt and display the number of lines, words, and characters it contains,
you can follow these steps:

Step 1:Create the File wlcc.txt by using touch command.

Step 2: Write in the text file wlcc.txt by using echo command.

Step 3: Display the text which is in the wlcc.txt by using cat command.

Step 4: Display how many lines, words and characters are present in the file by using wc command.

WC: wc stands for word count. As the name implies, it is mainly used for counting purposes.
It is used to find out the number of lines, word count, byte and characters count in the files specified
in the file arguments.

Isha Choudhary 0827CI221065

33
Experiment No.7

Append ten more simple line to the file and display

In Linux, text files store information in plain text, and each line typically represents a piece of data.
Appending lines involves adding new information to the end of an existing file, preserving its current
content.

Step 1: Append Lines to the File


You can use the echo command to append lines.

Step 2: Display the Contents of the File


After appending the lines, you can display the entire contents of isha.txt using the cat command:

Isha Choudhary 0827CI221065

34
Experiment No.8

Study and use of commands and for changing file permission

In Linux, file permissions control who can read, write, or execute a file. Understanding how to
change file permissions is essential for system security and user management. The primary command
used to change file permissions is chmod.

File Permissions

Categories of Users

Figure: Categories of users

Types of Permissions

Figure: Types of Permissions

Isha Choudhary 0827CI221065

35
Permissions can be represented in two ways:

To change directory permissions in Linux, use the following:

Using the chmod Command


Syntax - chmod [options] mode file

●​ chmod +rwx filename to add permissions


●​ chmod -rwx directoryname to remove permissions.
●​ chmod +x filename to allow executable permissions.
●​ chmod -wx filename to take out write and executable permissions.
Note that “r” is for read, “w” is for write, and “x” is for execute.

You can also use octal notations like this.

Isha Choudhary 0827CI221065

36
1.To Check the Permission of Files in Linux.

Command- ls -l

2. To give “execute” permission to the world (“other”) for file “wlcc.txt”.

Command - chmod o+x wlcc.txt

3.To revoke all the read(r), write(w), and execute(x) permission from all user(u), group(g), and
others(o) for the file wlcc.txt.

Command- chmod ugo-rwx wlcc.txt

4.To add read(r) and write(w) permission to both user(u) and group(g) and revoke execute(x)
permission from others(o) for the file wlcc.txt.

Command- chmod ug+rw,o-x wlcc.txt

Isha Choudhary 0827CI221065

37
Experiment No. 9

Aim: Write down shell script for following :

Shell Scripting

Usually, shells are interactive, which means they accept commands as input from users and execute
them. However, sometimes we want to execute a bunch of commands routinely, so we have to type in
all commands each time in the terminal.
As a shell can also take commands as input from file, we can write these commands in a file and can
execute them in shell to avoid this repetitive work. These files are called Shell Scripts or Shell
Programs. Shell scripts are similar to the batch file in MS-DOS. Each shell script is saved with `.sh`
file extension e.g., myscript.sh.
A shell script has syntax just like any other programming language. If you have any prior experience
with any programming language like Python, C/C++ etc. It would be very easy to get started with it.
A shell script comprises the following elements –
●​ Shell Keywords – if, else, break etc.
●​ Shell commands – cd, ls, echo, pwd, touch etc.
●​ Functions
●​ Control flow – if..then..else, case and shell loops etc.

Why do we need shell scripts?

There are many reasons to write shell scripts:


●​ To avoid repetitive work and automation
●​ System admins use shell scripting for routine backups.
●​ System monitoring
●​ Adding new functionality to the shell etc.

Isha Choudhary 0827CI221065

38
Some Advantages of shell scripts
●​ The command and syntax are exactly the same as those directly entered in the command
line, so programmers do not need to switch to entirely different syntax
●​ Writing shell scripts are much quicker
●​ Quick start
●​ Interactive debugging etc.

Some Disadvantages of shell scripts


●​ Prone to costly errors, a single mistake can change the command which might be harmful.
●​ Slow execution speed
●​ Design flaws within the language syntax or implementation
●​ Not well suited for large and complex task
●​ Provide minimal data structure unlike other scripting languages. etc.

How to Create a Shell Script in linux


Shell is an interface of the operating system. It accepts commands from users and interprets them to
the operating system. If you want to run a bunch of commands together, you can do so by creating a
shell script. Shell scripts are very useful if you need to do a task routinely, like taking a backup. You
can list those commands and execute them all with just a single script.
Creating a Shell Script
Login to your Linux machine and open the terminal, navigate to the folder where you want to store
the shell script. Shell scripts end with the extension “.sh”. Let’s create our first shell script. Type in
touch script.sh
Now, this script file is not executable by default, we have to give the executable permission to this
file. Type in
chmod +x script.sh
Now, we will add some commands to this shell script. Open this shell script with any text editor of
your choice (command-line based or GUI based) and add some commands. We will use nano. Type in
nano script.sh
Add the following commands to test this shell script
echo This is my first shell script

Save the changes, and run the shell script by typing in


./script.sh

Isha Choudhary 0827CI221065

39
1.Write a shell script to print “Hello Learner”.

Script:

Output:

2.Write a bash script program to take run-time argument from the user as a name
and print “Greetings <Your name>”.

Script:

Output:

Isha Choudhary 0827CI221065

40
3.Demonstrate the shell script with different usage of variables.

Script:

Output:

4.Write a shell script to perform arithmetic operations.

(a)
Script:

Isha Choudhary 0827CI221065

41
Output:

4(b):

Script:

Output:

Isha Choudhary 0827CI221065

42
5.Write a shell script to take two values as an argument from the user and compare them.

Script:

Output:

Isha Choudhary 0827CI221065

43
6.Write a shell script to check whether the given input is even or odd.

Script:

Output:

7.Write a shell script to check whether a year is a leap year or not.

Script:

Isha Choudhary 0827CI221065

44
Output:

8.Write a shell script to check whether a number is prime or not.

Script:

Isha Choudhary 0827CI221065

45
Output:

9.To find the area and circumference of a circle.

Script:

Output:

Isha Choudhary 0827CI221065

46
10.To check the given number and its reverse are the same.

Script:

Output:

Isha Choudhary 0827CI221065

47
11.Demonstrate shell script with diff variable.

Script:


Output:

13.To check whether the entered string is a palindrome or not.

Script:

Isha Choudhary 0827CI221065

48
Output:

14.To check whether the entered number is an Armstrong number or not.

Script:

Output:

Isha Choudhary 0827CI221065

49
15.WAP to print prime numbers between 1 and 50.

Script:

Output:

Isha Choudhary 0827CI221065

50
16. Write a shell script to count the number of vowels in a line of text.
Script:

Output:

Isha Choudhary 0827CI221065

51
17. Write a Shell Script to find the smallest number from a set of numbers.

Script:


Output:

Isha Choudhary 0827CI221065

52
18.Write a Shell Script to display student grades.

Script:

Output:

Isha Choudhary 0827CI221065

53
19. Write a Shell Script to print marksheet, that takes five subjects marks at runtime and
calculate the percentage of a student.

Script:


Output:

Isha Choudhary 0827CI221065

54
Experiment No. 10

Case Study: Setting Up and Configuring Apache Tomcat, Samba, DNS/LDAP Services,
Firewall, and Proxy Server Configuration in a Networked Environment

Overview:

This case study focuses on the implementation of a networked environment that includes Apache
Tomcat for web applications, Samba for file sharing, DNS and LDAP for directory services,
firewall configurations for security, and proxy server settings for controlled internet access. The
environment is designed to support a medium-sized organization with a focus on security,
performance, and ease of management.

Objective:

A. Deploy Apache Tomcat for hosting Java-based web applications.


B. Set up Samba for file sharing across different operating systems.
C. Implement DNS and LDAP for centralized user management and resource location.
D. Configure a firewall to secure the network.
E. Set up a proxy server for controlled internet access and monitoring.

Environment Setup:

• Hardware:
A server with at least 16GB RAM, 4 CPU cores, and 500GB of storage.

• Operating System:
Ubuntu Server 22.04 LTS.

• Network Configuration:
Static IP addressing for servers, DHCP for client machines.

Isha Choudhary 0827CI221065

55
A. Deploying Apache Tomcat

Installation Steps:

1. Install Java Development Kit (JDK)

2. Download Apache Tomcat:


wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.62/bin/apache tomcat-9.0.62.tar.gz

3. Extract and Configure:

4. Set Permissions:

5. Start Tomcat:

Configuration:

• Edit “server.xml” to configure the port and context paths.


• Ensure proper security settings in “web.xml” for web applications.

Isha Choudhary 0827CI221065

56
B. Setting Up Samba

Installation Steps:

1. Install Samba:

2. Configure Samba:

Edit /etc/samba/smb.conf to create a share:

3. Create Shared Directory:

4. Restart Samba Service:

Isha Choudhary 0827CI221065

57
C. Implementing DNS and LDAP

Installation Steps for DNS (Bind9):

1. Install Bind9

2. Configure Zone Files:

Edit /etc/bind/named.conf.local to add zones.

3. Restart Bind9

Installation Steps for LDAP (OpenLDAP):

1. Install OpenLDAP

2. Configure LDAP:
Use dpkg-reconfigure slapd to set up the domain and admin password.

3. Add Users:
Create LDIF files and use ldapadd to populate the directory.

Isha Choudhary 0827CI221065

58
D. Configuring the Firewall Installation and Configuration:

1. Install UFW

2. Allow Necessary Ports

E. Setting Up a Proxy Server


Installation Steps (Squid Proxy):

1.Install Squid:

2.Configure Squid:

3. Restart Squid Service:

Summary
This setup provides a secure, scalable infrastructure with Apache Tomcat for web applications,
Samba for file sharing, DNS and LDAP for centralized resource and user management, and
firewall/proxy configurations for network security. Following best practices in securing access and
monitoring logs helps in maintaining a reliable and compliant environment.

Isha Choudhary 0827CI221065

59
Isha Choudhary 0827CI221065

60

You might also like