oss unit2 up (1)
oss unit2 up (1)
VANIYAMBADI
PG and Department of Computer Applications
III BCA – Semester – VI
E-Notes (Study Material)
UNIT II:LINUX
Introduction: Linux Essential Commands-File system concept-Standard files-The Linux security
model-Vi Editor-partitions creation-Shell Introduction-String Processing-Investigation and
managing processes-Network Clients-Installing Application.
Learning Objectives:
1.To understand the concept of HTML, HTML5 and CSS.
2.To understand the concept of scripting code for a website.
3.To understand the concept of scripting code for a website.
4.To understand the fundamentals of PHP language combined with HTML.
5.To understand the fundamentals of PERL languages.
Course Outcome:
1.The student will be able to understand the concept of HTML, HTML5 and CSS.
2.The student will be able to learn to inspect and detect errors by going through each and every code
segment.
3.The student will be able to understand basic concept of Java script and MYSQL.
4.The student will be able to understand basic concept of PHP.
5.The student will be able to understand basic concept of PERL.
1
Linux kernel has the responsibilities of memory, process, and file management. As the Linux OS is
open source, professionals and developers can all contribute to the kernel. The system user space is the
administrative layer for configuration tasks and software installation. This layer includes the command
lines, daemons, processes that run in the background, and the desktop environment.
Linux History: A Story Of Origin
Linux has been around for some time now: in 1969, a group of developers at Bells Labs decided to
make a common software for all computers which would be known as Unix. Unix was written in
simple, easy-to-understand C language and its code was recyclable.
The fact that Unix's code was recyclable made parts of the code which were known as kernel installable
on different systems. The code was open source, but then Unix was restricted to large organizations
like universities and financial institutions that had mainframes and minicomputers.
In the 1980s, more organizations were creating their versions of Unix but none struck gold. 1991 saw
Linus Torvalds, a student at the University of Helsinki, Finland creates Linux for fun. The project
which was intended to be a free academic project became so successful that in 1992, he released his
Linux kernel under GNU General Public License.
Advantages and benefits of Linux:
The main advantage of Linux is it is an open-source operating system. This means the source
code is easily available for everyone and you are allowed to contribute, modify and distribute
the code to anyone without any permissions.
In terms of security, Linux is more secure than any other operating system. It does not mean
that Linux is 100 percent secure, it has some malware for it but is less vulnerable than any other
operating system. So, it does not require any anti-virus software.
The software updates in Linux are easy and frequent.
Various Linux distributions are available so that you can use them according to your
requirements or according to your taste.
Linux is freely available to use on the internet.
It has large community support.
It provides high stability. It rarely slows down or freezes and there is no need to reboot it after
a short time.
Linux vs Windows:
2
s.no Linux Windows
There is forward slash is used for Separating While there is back slash is used for
6.
the directories. Separating the directories.
Linux is widely used in hacking purpose based While windows does not provide much
8.
systems. efficiency in hacking.
3
s.no Linux Windows
Root user is the super user and has all Administrator user has all
10.
administrative privileges. administrative privileges of computers.
4
In the output we are harssh directory(folder for Windows OS that are moving to Linux),which is
present inside the home directory
$ pwd: Output: /home/harsh
•mkdir : The ‘$ mkdir’ stands for ‘make directory’ and it creates a new directory.We have used ‘$ cd’
(which is discussed below) to get into the newly created directory and again on giving ‘$ pwd’
command,we are displayed with the new ‘newfolder’ directory.
$ mkdir newfolder
$ cd newfolder
$ pwd
Output: /home/harssh/newfolder
•rmdir : The ‘$ rmdir’ command deletes any directory we want to delete and you can remember it by
its names ‘rmdir’ which stands for ‘remove directory’.
$ rmdir newfolder
•cd : The ‘$ cd’ command stands for ‘change directory’ and it changes your current directory to the
‘newfolder’ directory.You can understand this a double-clicking a folder and then you do some stuff in
that folder.
•ls : The ‘ls’ command simply displays the contents of a directory.
$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos
•touch : The ‘$ touch’ command creates a file(not directory) and you can simple add an extension such
as .txt after it to make it a Text File.
$ touch example
$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos example
•cp : This ‘$ cp ‘ command stands for ‘copy’ and it simply copy/paste the file wherever you want to.In
the above example, we are copying a file ‘file.txt’ from the directory harssh to a new directory new.
$ cp /home/harssh/file.txt /home/harssh/new/
5
•mv : The ‘$ mv’ command stands for ‘move’ and it simply move a file from a directory to another
directory.In the above example a file named ‘file.txt’ is being moved into a new directory ‘new’
$ mv /home/harssh/file.txt /home/harssh/new
•rm : The ‘$ rm ‘ command for remove and the ‘-r’ simply recursively deletes file. Try ‘$ rm
filename.txt’ at your terminal
$ rm file.txt
System Information:
1. date – Displays or sets the system date and time.
sh
CopyEdit
date
Example output:
yaml
CopyEdit
Wed Jan 31 12:34:56 UTC 2025
You can also format the output:
sh
CopyEdit
date "+%Y-%m-%d %H:%M:%S"
Example:
yaml
CopyEdit
2025-01-31 12:34:56
2. df (Disk Free) – Displays disk space usage of file systems.
sh
CopyEdit
df -h
6
Example output:
bash
CopyEdit
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 50G 50G 50% /
o -h makes it human-readable (GB, MB, etc.).
3. du (Disk Usage) – Shows the disk usage of files and directories.
sh
CopyEdit
du -sh /home/user
Example output:
arduino
CopyEdit
2.5G /home/user
o -s gives a summary.
o -h makes it human-readable.
Would you like additional options or examples?
4o
You said:
file operation in linux command gzip,tail,scp,sftp,cat
File Operations:
1. gzip – Compress files
sh
CopyEdit
gzip filename.txt
Compresses filename.txt to filename.txt.gz.
7
To decompress:
sh
CopyEdit
gunzip filename.txt.gz
To compress multiple files:
sh
CopyEdit
gzip file1 file2 file3
8
sh
CopyEdit
scp -r myfolder user@remote_host:/path/to/destination/
Specify a port (if not default SSH port 22):
sh
CopyEdit
scp -P 2222 file.txt user@remote_host:/path/to/destination/
9
Displays the contents of file.txt.
Concatenate multiple files:
sh
CopyEdit
cat file1.txt file2.txt > merged.txt
Number lines in a file:
sh
CopyEdit
cat -n file.txt
View a large file page by page:
sh
CopyEdit
cat file.txt | less
Additional Resources:
https://www.scaler.com/topics/linux-tutorial/file-system-of-linux/
https://www.geeksforgeeks.org/basic-linux-commands/
Practice Questions:
1. What are the most basic Linux Commands to learn for beginners?
2. How do I view files in a Linux Directory?
3. What is the Command to Create a New File in Linux?
4. What is the Linux Command for changing file permissions?
10
2.Kernalmode and user mode:
There are two modes of operation in the operating system to make sure it works correctly.
These are user mode and kernel mode. They are explained as follows −
User Mode
The system is in user mode when the operating system is running a user application such as handling
a text editor. The transition from user mode to kernel mode occurs when the application requests the
help of operating system or an interrupt or a system call occurs.
The mode bit is set to 1 in the user mode. It is changed from 1 to 0 when switching from user mode to
kernel mode.
Kernel Mode
The system starts in kernel mode when it boots and after the operating system is loaded, it executes
applications in user mode. There are some privileged instructions that can only be executed in kernel
mode.
These are interrupt instructions, input output management etc. If the privileged instructions are
executed in user mode, it is illegal and a trap is generated.
The mode bit is set to 0 in the kernel mode. It is changed from 0 to 1 when switching from kernel mode
to user mode.
An image that illustrates the transition from user mode to kernel mode and back again is −
11
Criteria Kernel Mode User Mode
12
Criteria Kernel Mode User Mode
Additional Resources:
https://www.geeksforgeeks.org/user-mode-and-kernel-mode-switching/
Practice Questions:
Why do we need dual mode in the operating system?
What is the transition from the user mode and kernel mode in the operating system?
Which mode is faster kernel mode or user mode?
13
Directories, also known as folders, are an integral part of the Linux file system. They serve as containers
for files and other directories and are used to organize and structure the file system. A directory can be
thought of as a virtual container that holds files and other directories within it.
One of the primary functions of directories in Linux is to provide a hierarchical structure for organizing
files. This structure starts at the root directory (/), and branches out into subdirectories as needed. With
the help of this hierarchical structure, complicated systems can be structured logically and organized.
This makes it simpler to locate and handle files on the system.
Each directory in Linux file system has a specific function, Some of a few key directories are listed
below :
/(rootdirectory):
The root directory is the top-level directory in the Linux file system. All other directories and
files are contained within the root directory.
/bin:
The /bin stands for binaries. This directory contains essential command-line tools and programs
that are required for basic system administration tasks.
/boot:
The /boot directory contains the boot loader files and kernel images needed to start the system.
/dev:
The /dev directory contains device files that represent hardware devices and virtual devices
such as terminals, printers, and disks.
/etc:
The /etc directory contains system configuration files that are used by various applications and
services on the system.
/home:
The /home directory contains the home directories of users on the system. Each user has their
own subdirectory within /home where they can store their personal files and settings.
/lib:
The /lib directory contains shared library files that are needed by various programs on the
system.
/media:
The /media directory is used to mount removable media such as CDs, DVDs, and USB drives.
/mnt:
The /mnt directory is used to mount file systems temporarily, such as network file systems or
disk images.
14
/opt:
The /opt directory is used to store additional software packages that are not part of the core
system.
/proc:
The /proc directory is a virtual file system that provides information about running processes
and system resources.
/run:
The /run directory contains temporary files that are created by system services and daemons.
/sbin:
The /sbin directory contains system binaries and administrative tools that are required for
system maintenance.
/srv:
The /srv directory is used to store data for services provided by the system.
/sys:
The /sys directory is a virtual file system that provides information about the system's hardware
and devices.
/tmp:
The /tmp directory contains temporary files that are created by applications and services
running on the system.
/usr:
The /usr directory contains user-level programs, libraries, documentation, and shared data files.
/var:
The /var directory contains variable data files that change frequently, such as log files and
system databases.
In Linux, everything is considered as a file. In UNIX, seven standard file types are regular, directory,
symbolic link, FIFO special, block special, character special, and socket. In Linux/UNIX, we have to
deal with different file types to manage them efficiently.
Categories of Files in Linux/UNIX
In Linux/UNIX, Files are mainly categorized into 3 parts:
1. Regular Files: Standard files like text, executable, or binary files.
2. Directory Files: Files that represent directories containing other files and folders.
15
3. Special Files: This category includes block device files, character device files, symbolic links,
pipes, and socket files.
The easiest way to find out file type in any operating system is by looking at its extension such as .txt,
.sh, .py, etc. If the file doesn’t have an extension then in Linux we can use file utility.
In this article, we will demonstrate file command examples to determine a file type in Linux.
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.
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.
16
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.
Additional Resources:
https://www.geeksforgeeks.org/linux-file-system/
https://www.javatpoint.com/linux-file-system
Practice Questions:
17
The primary users of the LSM interface are Mandatory Access Control (MAC) extensions which
provide a comprehensive security policy. Examples include SELinux, Smack, Tomoyo, and AppArmor.
In addition to the larger MAC extensions, other extensions can be built using the LSM to provide
specific changes to system operation when these tweaks are not available in the core functionality of
Linux itself.
A list of the active security modules can be found by reading /sys/kernel/security/lsm. This is a comma
separated list, and will always include the capability module. The list reflects the order in which checks
are made. The capability module will always be first, followed by any “minor” modules (e.g. Yama)
and then the one “major” module (e.g. SELinux) if there is one configured.
AppArmor: AppArmor is MAC style security extension for the Linux ke
rnel. It implements a task centered policy, with task “profiles” being created and loaded from user
space. Tasks on the system that do not have a profile defined for them run in an unconfined state which
is equivalent to standard Linux DAC permissions.
LoadPin: LoadPin is a Linux Security Module that ensures all kernel-loaded files (modules, firmware,
etc) all originate from the same filesystem, with the expectation that such a filesystem is backed by a
read-only device such as dm-verity or CDROM. This allows systems that have a verified and/or
unchangeable filesystem to enforce module and firmware loading restrictions without needing to sign
the files individually.
SELinux: If you want to use SELinux, chances are you will want to use the distro-provided policies,
or install the latest reference policy release.
Smack: Smack is the Simplified Mandatory Access Control Kernel. Smack is a kernel based
implementation of mandatory access control that includes simplicity in its primary design goals. Smack
is not the only Mandatory Access Control scheme available for Linux. Those new to Mandatory Access
Control are encouraged to compare Smack with the other mechanisms available to determine which is
best suited to the problem at hand.
TOMOYO: TOMOYO is a name-based MAC extension (LSM module) for the Linux kernel.
Yama: Yama is a Linux Security Module that collects system-wide DAC security protections that are
not handled by the core kernel itself. This is selectable at build-time with
CONFIG_SECURITY_YAMA, and can be controlled at run-time through sysctls in
/proc/sys/kernel/yama:
Additional Resources:
https://www.kernel.org/doc/html/v4.16/admin-guide/LSM/index.html
Practice Questions:
1. What is AppArmor?
2. What is the Linux Security Module (LSM) framework?
18
3. How does LSM enhance security in the Linux kernel?
20
Commands Description
q Quit
21
Control Command (Scrolling) in vi Editor :
There are the following useful commands which can be used along with the Control Key. These
commands are helpful in saving time by navigating quickly in a file without manually scrolling.
Command Description
o Creates a new line for text entry below cursor location and switches to insert mode.
22
Command Description
O Creates a new line for text entry above cursor location and switches to insert mode.
Replaces single character under the cursor with any number of characters and switches
s to insert mode.
R Overwrites text from the cursor to the right, without switching to insert mode.
`Dw` Deletes from the current cursor location to the next word
`d^` Deletes from current cursor position to the beginning of the line.
`d$` Deletes from current cursor position to the end of the line.
23
Commands Description
24
2. View Partition on a Specific Disk
Below command is used to view all disk partitions on device ‘/dev/sda’.
$ sudo fdisk -l /dev/sda
25
Note: This will prompt for a command. Type ‘m’ for seeing all the operations which can perform on
‘/dev/sda’. After pressing m you will get:
26
Run ‘w’ command to write the changes and reboot your system.
5. Delete a Hard Disk Partition
To delete a partition for the hard disk and free up space occupied by that partition for example
‘/dev/sdb’. Go to the command menu using following:
$ sudo fdisk /dev/sda
and then type ‘d’ to go to the delete partition menu. It will prompt the partition number you want to
delete(type the number).
Run ‘w’ command to write the changes and reboot the system.
6. How to view the size of your Partition
$ sudo fdisk -s /dev/sda
Note:
To check for the manual page of ‘fdisk’ command, use the following command:
$ man fdisk
To see the help message and listing of all options, use the following command option:
$ sudo fdisk -h
27
Additional Resources:
https://www.geeksforgeeks.org/vi-editor-unix/
Practice Questions:
•Terminal
What is Kernel?
The kernel is a computer program that is the core of a computer’s operating system, with complete
control over everything in the system. It manages following resources of the Linux system –
•File management
•Process management
•I/O management
•Memory management
•Device management etc.
What is Shell?
A shell is special user program which provide an interface to user to use operating system services.
Shell accept human readable commands from user and convert them into something which kernel can
understand.
28
Shell can be accessed by user using a command line interface. A special program called Terminal in
linux/macOS or Command Prompt in Windows OS is provided to type in the human readable
commands such as “cat”, “ls” etc. and then it is being execute. The result is then displayed on the
terminal to the user. A terminal in Ubuntu 16.4 system looks like this –
In above screenshot “ls” command with “-l” option is executed. It will list all the files
in current working directory in long listing format. Working with command line shell is bit difficult
for the beginners because it’s hard to memorize so many commands. It is very powerful, it allows user
to store commands in a file and execute them together. This way any repetitive task can be easily
automated. These files are usually called batch files in Windows and Shell Scripts in Linux/macOS
systems.
2. Graphical Shells
Graphical shells provide means for manipulating programs based on graphical user interface (GUI), by
allowing for operations such as opening, closing, moving and resizing windows, as well as switching
focus between windows. Window OS or Ubuntu OS can be considered as
good example which provide GUI to user for interacting with program. User do not need to type in
command for every actions.A typical GUI in Ubuntu system –
Shell Scripting
Usually shells are interactive that mean, they accept command as input from users and execute them.
However some time we want to execute a bunch of commands routinely, so we have type in all
commands each time in terminal. As 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 eg. myscript.sh
Advantages of shell scripts
•The command and syntax are exactly the same as those directly entered in command line, so
programmer do not need to switch to entirely different syntax
•Writing shell scripts are much quicker
29
7.Shell string processing:
String Manipulation is defined as performing several operations on a string resulting change
in its contents. In Shell Scripting, this can be done in two ways: pure bash string manipulation, and
string manipulation via external commands.
Basics of pure bash string manipulation:
1.Assigning content to a variable and printing its content: In bash, ‘$‘ followed by the
variable name is used to print the content of the variable. Shell internally expands the variable with
its value. This feature of the shell is also known as parameter expansion
Syntax:
VariableName='value' echo $VariableName
Example:
2.To print length of string inside Bash Shell: ‘#‘ symbol is used to print the length of a string.
Syntax:
variableName=value
echo ${#variablename}
Example:
3.Concatenate strings inside Bash Shell using variables: In bash, listing the strings together
concatenates the string. The resulting string so formed is a new string containing all the listed strings.
Syntax:
var=${var1}${var2}${var3}
Example:
4. Concatenate strings inside Bash Shell using an array: In bash, arrays can also be used
to concatenate strings.
30
Syntax:
To create an array:
arr=("value1" value2 $value3) To print an array:
echo ${arr[@]}
Note: echo ${arr} is the same as echo ${arr[0]}
A process means program in execution. It generally takes an input, processes it and gives us
the appropriate output. Check Introduction to Process Management for more details about a process.
There are basically 2 types of processes.
Foreground processes: Such kind of processes are also known as interactive processes. These
are the processes which are to be executed or initiated by the user or the programmer, they can not be
initialized by system services. Such processes take input from the user and return the output.
31
Background processes: Such kind of processes are also known as non-interactive
processes. These are the processes that are to be executed or initiated by the system
itself or by users, though they can even be managed by users. These processes have a unique
PID or process if assigned to them and we can initiate other processes within the same terminal from
which they are initiated.
This command will be executed in the terminal and we would be able to execute another
command after the execution of the above command.
To-get-the-list-of-jobs-which-are-either-running-or-stopped.It will display the stopped
processes in this terminal and even the pending ones.
To-execute-pending-and-force-stopped-jobs-in-the-background. This will start the
stopped and pending processes in the background.
To-get-details-of-a-process-running-in-background.
To run all the pending and force stopped jobs in the foreground. To run a process in the
background without getting impacted by the closing of the terminal.
&: To-run-a-process-in-background.-without-getting-impacted-by-the-closing-
of-terminal
To run processes with priority.
To get the list of all the running processes on your Linux machine.
Additional Resources:
https://www.geeksforgeeks.org/introduction-of-process-management/
Practice Questions:
1. What are the key steps in conducting a thorough investigation?
2. How do you ensure objectivity and accuracy in an investigation?
3. What techniques can be used to gather and analyze evidence effectively?
32
4. How do you handle confidentiality and ethical considerations in an investigation?
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.
33
Here is a list of Networking and Troubleshooting commands:
34
What are Linux networking clients, and how do they function?
What are the key differences between a Linux networking client and a server?
How do you configure a static IP address for a Linux networking client?
Additional Resources:
https://www.geeksforgeeks.org/how-to-install-software-in-linux/
Below are some methods where we use both the packages as well as prompts and repositories in
order to install a particular software in Linux.
35
Method 1: Install The Software In Linux Using Terminal
The APT tool is a built in tool available in the versions of the Linux operating systems, the APT tool
can easily be used for installation as well removal of any particular software that we want. Find more
apt commands in Linux with examples
36
Step 1: Open Software Store
First, go to the desktop of your OS, then simply click on the "store" icon that is available at the left
side, as you can see in the image below.
open-software-store
open software store.
Step 2: Search for the Particular Software to Install
In this step, you click on the search option that is available to the left side of the Window, and enter
the name of the software that you want to install, if the software is present in the store and it will
show up after you search it, as seen below:
search-on-store
Search for the Particular Software.
Step 3: Click on Install button.
Now simply click on the install button once you find the software that you want to install as you can
see in the image below.
click-on-install
Click on Install.
Once the file is downloaded and installed, you can easily open and run the software.
37
You can also check out this article How to Install and Configure Synaptic Package Manager in
Ubuntu?
open-synaptic
Open Synaptic Software.
Step 3: Search for Required Package
Click on the search button that is present in the top right corner, and then search for the particular file
or software package that we want to install.
search-package
Search for Required Package.
Step 4: Mark for Installation and Install
Now click on the mark for installation option after selecting your required package that you want to
install, then simply click on the "apply" option as you can see in the image below.
synaptic-package-manager
Mark for Installation and Install.
Now the software will be installed automatically once the downloading of package is completed.
Practice Questions:
What are the different methods for installing software applications in Linux?
How do package managers simplify software installation in Linux?
Additional Resources:
https://www.geeksforgeeks.org/how-to-install-software-in-linux/
38