0% found this document useful (0 votes)
3 views

oss unit2 up (1)

The document provides study material for a course on Open Source Software, focusing on Linux in particular. It covers essential Linux commands, the history and advantages of Linux, comparisons with Windows, and the distinction between kernel mode and user mode. Additionally, it includes practical commands for file operations and system information, along with learning objectives and course outcomes for students.

Uploaded by

then mozhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

oss unit2 up (1)

The document provides study material for a course on Open Source Software, focusing on Linux in particular. It covers essential Linux commands, the history and advantages of Linux, comparisons with Windows, and the distinction between kernel mode and user mode. Additionally, it includes practical commands for file operations and system information, along with learning objectives and course outcomes for students.

Uploaded by

then mozhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

MARUDHAR KESARI JAIN COLLEGE FOR WOMEN (AUTONOMOUS)

VANIYAMBADI
PG and Department of Computer Applications
III BCA – Semester – VI
E-Notes (Study Material)

Core Course -1: Open Source Software Code:FCA61

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.

Introduction: Linux Essential Commands:


Linux is an open-source operating system that is used for computers, servers, mainframes, mobile
devices, and embedded devices. Linux is one of the most widely supported operating systems as it is
available on almost every major computer platform, including x86, ARM, and SPARC.
There are several Linux OS versions available: each version manages hardware resources, launches
and handles applications, and provides some sort of user interface. Linux has been used in different
ways for web servers, network operations, specific computing tasks, running databases, endpoint
computing, and running mobile devices with OS versions like Android. Linux is made up of
components like the kernel, system user space, and applications. The Linux kernel is the base
component of the Linux operating system that manages resources and communicates with the
hardware.

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

While windows are the not the open


1. Linux is a open source operating system.
source operating system.

2. Linux is free of cost. While it is costly.

3. It’s file name case-sensitive. While it’s file name is case-insensitive.

4. In linux, monolithic kernel is used. While in this, hybrid kernel is used.

Linux is more efficient in comparison of


5. While windows are less efficient.
windows.

There is forward slash is used for Separating While there is back slash is used for
6.
the directories. Separating the directories.

While it provides less security than


7. Linux provides more security than windows.
linux.

Linux is widely used in hacking purpose based While windows does not provide much
8.
systems. efficiency in hacking.

There are 4 types of user account –


There are 3 types of user account –
9. (1) Administrator , (2) Standard , (3)
(1) Regular , (2) Root , (3) Service account
Child , (4) Guest

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.

Linux file naming convention in case


sensitive. Thus, sample and SAMPLE are 2 In Windows, you cannot have 2 files
11.
different files in Linux/Unix operating with the same name in the same folder.
system.

1.Linux Essential commands:


A Linux command is a program or utility that runs on a command line. A command line is an interface
that accepts lines of text and processes them into instructions for your computer. A graphical user
interface is an abstraction of command line programs.
A flag is a method of passing options to commands that you run: in most cases, flags are optional. Flags
can be invoked using hyphens and double hyphens in the system. An argument or parameter is the input
you give to a command to ensure it runs properly.
Usually, the argument is a file path but it can be anything you type in the terminal. Argument execution
will depend on the order in which the arguments are passed to the function. If you want to send in
command, your first point of action should be to fire a terminal.
You can fire a terminal in Linux by using Ctrl + Alt + T. Alternatively, you can search your application
wall for "terminal."

Basic unix commands:


•who : The ‘$ who’ command displays all the users who have logged into the system currently.As
shown above on my system I am the only user currently logged in.The thing tty2 is terminal line the
user is using and the next line gives the current date and time
$ who: Output: harssh tty2 2017-07-18 09:32 (:0)
•pwd : The ‘$pwd’ command stands for ‘print working directory’ and as the name says,it displays the
directory in which we are currently (directory is same as folder for Windows OS users).

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

2. tail – View the last few lines of a file


sh
CopyEdit
tail -n 10 logfile.txt
 Shows the last 10 lines of logfile.txt.
 Follow a file in real-time:
sh
CopyEdit
tail -f logfile.txt
 Default output is 10 lines if -n is not specified.

3. scp – Securely copy files between systems


sh
CopyEdit
scp file.txt user@remote_host:/path/to/destination/
 Copies file.txt to a remote system.
 Copy a directory recursively:

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/

4. sftp – Secure File Transfer Protocol (interactive file transfer)


sh
CopyEdit
sftp user@remote_host
 Connects to the remote system for file transfer.
 Common commands inside sftp:
sh
CopyEdit
put localfile.txt # Upload file
get remotefile.txt # Download file
ls # List remote files
cd /path/ # Change directory on remote system
exit # Exit sftp

5. cat – View, concatenate, and manipulate files


sh
CopyEdit
cat file.txt

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 −

Difference Between Kernel Mode and User mode

Criteria Kernel Mode User Mode

In user mode, the application


In kernel mode, the program program do not have direct
Access to Resources has direct and unrestricted access to system resources. In
access to system resources. order to access the resources, a
system call must be made.

11
Criteria Kernel Mode User Mode

In Kernel mode, the whole


In user mode, a single process
Interruptions operating system might go
fails if an interrupt occurs.
down if an interrupt occurs

Kernel mode is also known as User mode is also known as the


Modes the master mode, privileged unprivileged mode, restricted
mode, or system mode. mode, or slave mode.

In kernel mode, all processes


In user mode, all processes get
Virtual address space share a single virtual address
separate virtual address space.
space.

In kernel mode, the


While in user mode the
applications have more
Level of privilege applications have fewer
privileges as compared to user
privileges.
mode.

As kernel mode can access


While user mode needs to
both the user programs as well
Restrictions access kernel programs as it
as the kernel programs there
cannot directly access them.
are no restrictions.

The mode bit of kernel-mode While the mode bit of user-


Mode bit value
is 0. mode is 1.

It can only make references to


It is capable of referencing
Memory References memory allocated for user
both memory areas.
mode.

12
Criteria Kernel Mode User Mode

A system crash in kernel mode


In user mode, a system crash
is severe and makes things
System Crash can be recovered by simply
more complicated.
resuming the session.

Only essential functionality is User programs can access and


Access permitted to operate in this execute in this mode for a
mode. given system.

The user mode is a standard


The kernel mode can refer to and typical viewing mode,
any memory block in the which implies that information
system and can also direct the cannot be executed on its own
Functionality
CPU for the execution of an or reference any memory
instruction, making it a very block; it needs an Application
potent and significant mode. Protocol Interface (API) to
achieve these things.

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?

3.Linux File System Concept and Standard Files:


Linux Directory Structure

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.

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.

2. JFS File System

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.

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 has
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 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.

Additional Resources:

https://www.geeksforgeeks.org/linux-file-system/
https://www.javatpoint.com/linux-file-system

Practice Questions:

1.What is the Linux File System?


2.What is Linux File System Structure

Linux security module:


The Linux Security Module (LSM) framework provides a mechanism for various security checks to be
hooked by new kernel extensions. The name “module” is a bit of a misnomer since these extensions
are not actually loadable kernel modules. Instead, they are selectable at build-time via
CONFIG_DEFAULT_SECURITY and can be overridden at boot-time via the "security=.
.." kernel command line argument, in the case where multiple LSMs were built into a given kernel.

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?

4.Vi editor with commands


The vi editor is elaborated as visual editor. It is installed in every Unix system. In other words, it is
available in all Linux distros. It is user-friendly and works same on different distros and platforms. It
is a very powerful application. An improved version of vi editor is vim.

The vi editor has two modes:


Modes of Operation in the vi editor
There are three modes of operation in vi:

Here are three modes of operations on the vi editor


Vi Command Mode :
When vi starts up, it is in Command Mode. This mode is where vi interprets any characters we type as
commands and thus does not display them in the window. This mode allows us to move through a file,
and delete, copy, or paste a piece of text. Enter into Command Mode from any other mode, requires
pressing the [Esc] key. If we press [Esc] when we are already in Command Mode, then vi will beep or
flash the screen.
19
Vi Insert mode:
This mode enables you to insert text into the file. Everything that’s typed in this mode is interpreted as
input and finally, it is put in the file. The vi always starts in command mode. To enter text, you must
be in insert mode. To come in insert mode, you simply type i. To get out of insert mode, press the Esc
key, which will put you back into command mode.
Vi Last Line Mode (Escape Mode):
Line Mode is invoked by typing a colon [:], while vi is in Command Mode. The cursor will jump to
the last line of the screen and vi will wait for a command. This mode enables you to perform tasks such
as saving files and executing commands.

Moving within a File (Navigation) in Vi Editor :


To move around within a file without affecting text must be in command mode (press Esc twice). Here
are some of the commands that can be used to move around one character at a time.
Commands Description

`k` Moves the cursor up one line.

`j` Moves the cursor down one line.

`h` Moves the cursor to the left one-character position.

`l` Moves the cursor to the right one-character position.

`0` Positions cursor at beginning of line.

`$` Positions cursor at end of line.

`W` Positions cursor to the next word.

`B` Positions cursor to previous work.

`(` Positions cursor to beginning of current sentence.

`)` Positions cursor to beginning of next sentence.

20
Commands Description

`H` Move to top of screen.

`nH` Moves to nth line from the top of the screen.

`M` Move to middle of screen.

`L` Move to bottom of screen.

`nL` Moves to nth line from the bottom of the screen.

Save and Exit in Vi Editor in Linux:


Need to press [Esc] key followed by the colon (:) before typing the following commands:
Commands Description

q Quit

q! Quit without saving changes i.e. discard changes.

r [file_name] Read data from file called [file_name]

wq Write and quit (save and exit).

w Write to file called [file_name] (save as).

w! Overwrite to file called [file_name] (save as forcefully).

!cmd Runs shell commands and returns to Command mode.

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

CTRL+d moves the screen down by half a page.

CTRL+f moves the screen down by a full page.

CTRL+u moves the screen up by half a page.

CTRL+b moves the screen up by a full page.

CTRL+e moves the screen up by one line.

CTRL+y moves the screen down by one line.

CTRL+I redraw the screen.

Inserting and Replacing text in Vi Editor :


To edit the file, we need to be in the insert mode. There are many ways to enter insert mode from the
command mode.
Command Description

i Inserts text before current cursor location

a Insert text after current cursor location

A Insert text at the end of current line

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.

Deleting Characters and Lines in Vi Editor :


Here is the list of important commands which can be used to delete characters and lines in an opened
file.
Command Description

`X` (Uppercase) Deletes the character before the cursor location.

`x` (Lowercase) Deletes the character at the cursor location.

`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.

`Dd` Deletes the line the cursor is on.

Copy and Paste in Vi editor in Linux:


Copy lines or words from one place and paste them in another place by using the following commands.
Commands Description

Yy Copies the current line.

9yy Yank current line and 9 lines below.

p Puts the copied text after the cursor.

23
Commands Description

P Put the yanked text before the cursor.

5.Creating a new partitions in Linux:

What is ‘fdisk’ command?


fdisk allows you to create a maximum of four primary partitions and the number of logical partitions
depends on the size of the hard disk you are using. It allows the user:
 To Create space for new partitions.
 Organizing space for new drives.
 Re-organizing old drives.
 Copying or Moving data to new disks(partitions).
Syntax:
fdisk [options] device
or
fdisk -l [device...]
Here’s a breakdown of some commonly used options in ‘fdisk’:
 ‘-l’: Lists the partition tables for specified disks or all disks if no disk is specified.
 ‘-s‘: Reports the size of a specified partition.
 ‘-d’: Dumps the partition table to a file.
 ‘-u‘: Shows the exact data placement on the disk in units.
 ‘-b’: Allows specification of sector size, useful for disks with non-standard sector sizes.
‘fdisk’ command examples in Linux
Let us look at some of the ways in which ‘fdisk’ command can be used in Linux.
1. View All Disk Partitions
The first thing to do before doing any thing with the disks and partition is to view basic details about
all available partition in the system. The below command is used to list the partitions on your system
and see their /dev names. For example ‘/dev/sda’, ‘/dev/sdb’ or ‘/dev/sdc’.
$ sudo fdisk -l

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

3. View all fdisk Commands


To see all the command which are available under fdisk command you can use ‘/dev/sda’ partition
with ‘fdisk’ command.
$ sudo fdisk /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:

4. Create a Hard Disk Partition


For this go inside the hard drive partition that is the ‘/dev/sda’ partition, and use the following
command:
$ sudo fdisk /dev/sda
Now you have to type n to create new partition and then type ‘p’ for making a primary partition and
‘e’ for making an extended or logical partition depending on the type of partition to make.

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:

1. What is the difference between vi and vim editor?


2. How do you search for a word in vi editor?
3. What is disk partitioning in Linux, and why is it necessary?
4. What are the common partitioning schemes used in Linux?

6.Linux Shell: Introduction


If you are using any major operating system you are indirectly interacting to shell. If you are running
Ubuntu, Linux Mint or any other Linux distribution, you are interacting to shell every time you use
terminal. we have to get familiar with following terminologies:
•Kernel
•Shell

•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.

Shell is broadly classified into two categories –

•Command Line Shell


•Graphical shell
1.Command Line Shell

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

•Interactive debugging etc.

Disadvantages of shell scripts

•Slow execution speed

Not well suited for large and complex task

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]}

5. Extract a substring from a string: In Bash, a substring of characters can be extracted


from a string.
Syntax:
${string:position} --> returns a substring starting from $position till end

${string:position:length} --> returns a substring of $length characters starting from $position.


Additional Resources:
https://www.geeksforgeeks.org/introduction-linux-shell-shell-scripting/
Practice Questions:
1. What is a Linux Shell?
2. What are the different types of shells available in Linux?
3. How do you check which shell you are currently using?
4. What is the default shell in most Linux distributions?
5. How do you switch from one shell to another in Linux?

8.Investigation And Process management:

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.

Managing the Processes


Example of foreground process.

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?

9.Linux networking clients:

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:

ifconfig Display and manipulate route and network interfaces.

Traceroute Network troubleshooting utility.

Ping To check connectivity between two nodes.

Netstat Display connection information.

Dig Query DNS related information.

Nslookup Find DNS related query.

Route Shows and manipulate IP routing table.

Host Performs DNS lookups.

Iwconfig Used to configure wireless network interface.

Hostname To identify a network name.

curl or wget To download a file from internet.

Mtr Combines ping and tracepath into a single command.

Whois Will tell you about the website's whois.

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/

10.Install Software Applications in Linux:


Linux offers a flexible and powerful environment for running software, but if you're new to the
platform, you might wonder how to install software in Linux. Unlike other operating systems,
Linux provides multiple ways to install applications, whether through package managers, terminal
commands, or graphical interfaces. This guide will walk you through the most common methods
to install software in Linux, ensuring you can get your programs up and running quickly and
efficiently.
In the case of Linux, it becomes a bit of a difficult task for you to Install Software Applications in
Linux that you want so in this article we will learn and understand how we can install software that
we want in the Linux operating system.

Using Repository to Install Software in Linux


For at least more than a decade the Linux Systems has used software repositories in order to
distribute software that they want the repository in a public server that manages and hosts installable
software packages. These installable packages contain the necessary data required for any software to
be installed, just like in the Windows we have .exe depositories contain all the files and folders of a
particular software. Linux distribution also provides a command line interface(CLI) also owns
graphical interface (GUI) and it acts as a Microsoft store that we see in the Windows.

Learn more about CLI and GUI in Linux Operating System

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

Step 1: Update Package Index


In this example, we will install the synaptic which is a package installer that we will use in the
installation of other software later in the method, for this we will have to first run the following
command in order to update the package index:

sudo apt-get update


update-index
sudo apt-get update.
Step 2: Install the Package
In this step, we will have to enter the following commands and it will install the software (in this
case, synaptic) for us, we can also rename the package name by any other package name, but make
sure that the package name is accurate:

sudo apt-get install synaptic


install-synaptic
sudo apt-get install synaptic.
You will see an input prompt, which will ask if you want to continue or not, for installing the
software you will have to simply type "Y" and your software will begin downloading as well as
installing.

Method 2: Install Software In Linux via Software Store


The Linux operating system offers the software store which can be easily used in order to install any
software that can be installed in the Linux system. for this, this method is the easiest method as it
requires very less amount of technical work, let's learn step by step how we can do this:

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.

Method 3: Install Software Application In Linux via Synaptic


In the method 3 we learned how we can install any software using APT, now we will use the same
software (Synaptic) to install packages.

Step 1: Follow Method 1 and Install Synaptic


Simply follow the method 1 and then move to step 2.

37
You can also check out this article How to Install and Configure Synaptic Package Manager in
Ubuntu?

Step 2: Open Synaptic Software


Go to the start menu and open synaptic software searching for it, or by visiting System >
Administration > Synaptic Package Manager, it will look something like this.

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

You might also like