Linux Full

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

lOMoARcPSD|16716358

Linux Full

BSc Computer Science (Mahatma Gandhi University)

Studocu is not sponsored or endorsed by any college or university


Downloaded by Hentai Senpai (senpaihentai251@gmail.com)
lOMoARcPSD|16716358

S4 BCA A LINUX MI

Unit-1 - Overview of Linux: What is Linux, Linux‘s root in Unix, Common Linux Features, advantage of
Linux, Overview of UNIX and Linux architectures, Linux files system, hardware requirements for Linux,
Linux standard directories. Commands for files and directories cd, ls, cp, rm, mkdir, rmdir, pwd, file, more,
less, Creating and viewing files using cat, file comparisons.

History of Linux

In 1969, Ken Thompson and Dennis Ritchie developed a small, general-purpose operating system written
in Assembly Language called UNIX.
 In 1973, Ken Thompson and Dennis Ritchie rewrote the UNIX operating system in C.
 Many vendors, such as Sun, IBM, and Hewlett-Packard, purchased the source code of UNIX and
developed their own version of UNIX. The source code of these versions was not freely available, so
the developers had to wait for a long time for the release of bug fixes.
 In 1984, Richard Stallman's Free Software Foundation (FSF) began the GNU (gnu's Not UNIX)
project to create a free version of the UNIX operating system. The FSF built a number of tools that
could be freely used, read, modified, and redistributed but the kernel was still not created.
 In 1991, Linus Torvalds developed a kernel and called it Linux.
 In 1992, the Linux kernel was combined with the incomplete GNU system to form a completely free
operating system. This operating system is called GNU/Linux because it is a combination of GNU
and Linux. The GNU/Linux operating system is commonly referred to as the Linux operating
system.
Distributors of Linux
There are several distributors of Linux. All the distributors use the Linux kernel.
Some of the distributors of Linux are:
 Red Hat
 Ubuntu
 Caldera
 Mandrake
 Debian
 SuSE,
 Slackware

1 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

Official mascot
Tux is a penguin character and the official brand character of the Linux kernel. Tux is the most commonly
used icon for Linux, although different Linux distributions depict Tux in various styles.

Linux is open Source


 Linux follows the open development model. The source code of the Linux kernel is available for
study and modifications on the Internet.
 The current development version of Linux is always open to users. Users can also suggest
modifications to the kernel code. When a new version of Linux is released, users can work on the
new version to fix bugs, if any. To maintain stability, Linus Torvalds ensures strict quality control
and then merges all the new code into the kernel. This is a major reason for the success of Linux
Features/ Advantages of Linux
1. Open Source: Open source software is software with source code that anyone can inspect, modify,
and enhance. Linux source code is freely available.
2. Multi-User: Linux is a multiuser system means multiple users can login and access system resources
3. Multiprogramming: Allows many programs to be executed simultaneously by different users.
4. Time-sharing: Is a concept that allows multiple programs to share CPU time for their execution.
Each program gets CPU time for a specific time period for its execution. After the specified time
period for program execution is expired, the program is put back in the sequence to wait its turn
again. The next program in the sequence is allotted the CPU time for its execution.
5. Multitasking: Is a concept that enables execution of multiple tasks simultaneously. If one task is
waiting for the completion of an activity, such as getting input from the keyboard, the CPU, instead
of wasting time, starts executing the next task.

2 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

6. Portability: Portability means software can works on different types of hardware in same way. Linux
kernel and application programs support their installation on any kind of hardware platform.
7. Hierarchical File System: Linux provides a standard file structure in which system files/ user files
are arranged.
8. Shell: Linux provides a special interpreter program which can be used to execute commands of the
operating system.
9. Security: Linux provides user security using authentication features like password protection/
controlled access to specific files/ encryption of data.
10. Free to use (Low Cost): Linux is freely available on the web to download and use. We do not need to
buy the license for it as Linux and many of its software come with GNU General Public License.
11. Software Updates: In Linux you encounter a larger number of software updates. These software
updates are much faster than updates in any other operating system. Updates in Linux can be done
easily without facing any major issue or concern.
12. Customization: You can customize any feature, add or delete any feature according to your need as
it is an open source operating system.
13. Various Distributions: There are many distributions available also called bistros of Linux. It provides
various choices or flavors to the users. You can select any distributor according to your needs.
14. Support for application development: Offers an excellent platform for many development languages,
such as C, C++, JAVA, Python, PHP, and Perl.
15. Graphical User Interface (GUI): Is a user interface that helps the users to interact with the computer
easily. The GUI of Linux is X Window system. The X Window system consists of two subsystems:
server and client. Linux has a number of GUIs called Desktop Environments, such as K Desktop
Environment (KDE) and GNU Object Model Environment (GNOME).

Linux File System


Linux divided physical disks into logical disks called partitions.
Each partition is a standalone file system.
A File system is made of certain Blocks. All the blocks belonging to the file system are logically divided
into four parts.

3 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

1. Boot Block: This represents the beginning of the file system. It contains a program called 'bootstrap
loader ‘which is executed when we 'boot' our machine. Although only one boot block is needed to
start up the system, all file systems contain one (possibly empty) boot block.
2. Super Block: The super block describes the state of the file system - how large it is, how many files
it can accommodate, It contains information like:

 Size of the file system


 Number and list of free blocks on the system
 Index to the next free block on the list
 Size of the inode list
 Number and list of free inodes
 Index to the next free inode on the list
 Flags to indicate modification of super block

3. Inode Table- The information related to all these files (not the contents) is stored in an Inode Table
on the disk. For each file, there is an inode entry in the table. These details are:
 Owner of the file
 Group to which the owner belongs
 Type of file
 File access permissions
 Date and time of last access
4. Data Block- These contain the actual file contents. An allocated data block can belong to only one
file in the file system.
Linux Directory Structure/Linux Standard Directories
 The Linux file system looks like a tree.
 The file system begins with a directory known as root. The root directory is denoted as slash(/). All
files and directories are logically contained inside the root directory.
 The root Directory is subdivided into subdirectories like Bin, Boot ,home ,usr, etc, dev etc
.

4 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

1. /bin: Bin directory stores many utilities available in linux. These utilities are commands in the Linux
operating system Many Linux commands, such as cat, cp, ls, more, and tar, are locate in /bin
2. /home: Home directory is the parent to the home directories of users which contains the home
directories of all the users.
3. /dev: contains all device files. Linux treats each device as a special file. All such files are located in
/dev.
4. /lib: Lib directory contains data libraries for the compilers, such as C Language routine installed in
the Linux OS.
5. /usr: Stores the operating system files that are not required during the startup process
6. /boot: contains the Linux kernel and other files.
7. /etc : Contains the data related to the operating system, including the essential operating system
programs and configuration files

ARCHITECTURE OF LINUX

Linux architecture consists of the following components:

1. Kernel
2. Shell
3. Utilities and application programs
1. Kernel
 Kernel is the core of the Linux operating system.
 It provides services for all other components of the operating system.
 Kernel controls the resources of a computer by allocating them to different Linux users and tasks
 It interacts directly with the hardware.

5 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

 The kernel forms an interface between the user and the hardware.
 Linux Kernel performs: I/O management, process management, device & file management and
memory management.

2. Shell

 Shell is a user interface that helps a user to interact with the Linux operating system.
 Shell provides services requested by Linux users, such as viewing a file and creating or removing a
directory or a file.
 It hides the complex hardware details from the Linux users.
 Shell is used as a Command Line Interpreter (CLI) to run commands and programs.
 Acts as a mediator between kernel and the user
3. System Utilities
 The utilities in Linux are collections of programs that provide day-to-day processing requirements,
such as searching a word in a file and viewing access permissions of files.
 These programs are invoked through the shell of the Linux operating system.

COMMANDS FOR FILES AND DIRECTORIES


1. PWD
The pwd command is a command line utility for printing the current working directory. It will print
the full system path of the current working directory to standard output.

6 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

 pwd
/home/student/D1
Here the user are currently in the Directory D1
2. CD
The cd Command. The cd command is used to change the current directory (i.e., the directory in
which the user is currently working)
 CD [directory] to move inside a subdirectory
 CD / This command is used to change directory to the root directory, the
root directory is the first directory in your file system hierarchy.
 CD Dir1/Dir2/Dir3 This Command is used to Change the directory to Dir3 by giving the
relative path Name
 CD This command is used to change directory to the home directory.
 CD .. This command is used to move to the parent directory of current
directory or the directory one level up from the current directory.

3. MKDIR
MKDIR command in Linux allows the user to create directories (also referred to as folders in some
operating systems).
 mkdir BCAS4 The mkdir command creates a directory called ‘BCAS4’.
 mkdir –p ABC/XYZ/PQR The option –p allows you to create multiple generations
of directories. If the ABC and XYZ Directories not
exists it will be created and inside XYZ , PQR is
created.
4. RMDIR
rmdir command is used remove empty directories from the file system in Linux. The rmdir
command removes each and every directory specified in the command line only if these directories
are empty. So if the specified directory has some directories or files in it then this cannot be removed
by rmdir command.
 rmdir BCAS4 The rmdir command removes a directory called ‘BCAS4’.
 rmdir –p ABC/XYZ/PQR This will first remove the child directory and then
remove the parent directory.

7 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

 rm -r DIR1 To remove non-empty directories and all the files within them, use
the rm command with the-r (recursive) option
5. RM
To remove (or delete) a file in Linux from the command line, use either the rm (remove)
 rm filename To Remove File1
 rm filename1 filename2 filename3 To Remove Multiple Files
 rm *.pdf To Remove all the PDF Files
6. CP
To copy the contents of one file to another one use the following method. If destination file
doesn’t exist it will be created. If it exists Linux will over write the contents of destination file.
 cp F1 F2 To Copy the Contents of File F1 to F2
 cp F1 F2 Dir1 To Copy the Files F1 and F2 to the Directory Dir1
 cp ABC/XYZ/F1 DIR1/F2 Here F1 is copied from the directory ABC/XYZ to the
Directory DIR1. The New Name is F2 for the File.
7. MV
mv is for moving a file.mv stands for move. mv is used to move one or more files or directories from
one place to It has two distinct functions:
(i) It rename a file or folder.
(ii) It moves group of files to different directory.
 mv F1 F2 To Rename the File F1 to F2
 mv Dir1 Dir2 To Rename the Directory D1 to D2
 mv F1 F2 Dir1 To move the Files F1 and F2 to the directory Dir1

8. FILE
File command is used to determine the type of a file.
 File F1 To display the type of File F1
 File * To Display all the files type in the current directory
 File Dir1/* To Display all the files type in the Dir1 directory

8 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

9. MORE
More command is used to view the text files in the command prompt, displaying one screen at a time
in case the file is large (For example log files). The more command also allows the user do scroll up
and down through the page.
More command pauses when the screen fills and waits for pressing a spacebar key before it moves to
another screen full of text. A message at the bottom of the screen tells us the percentage of file that
has been displayed so far. We can press Ctrl-C to quit more command before reaching the end of
file.
 More F1
10. LESS
The less command works like more except that it moves both forward and backward in the file while
the command is running. We can use the B key on your keyboard to back up one screen or a
spacebar to move forward and display the next screen. Less command is faster than more command
because it does not load the entire file at once and allows navigation though file.
 Less F1
11. LS
List all the directories, or list the contents of the current or specified directory.
 Ls To display the contents of the current directory
 Ls –a To display hidden files in the current directory
 ls p* List all files starting with p followed by any other character
 ls ?ain List all files starting with any character but ends with ‘ain’
 ls /mydir/*x List all files in directory ‘mydir’ which end in ‘x’
 ls [aeiou]* List the files with the first character can be either a,e,i,o,u and
the remaining can be any other letter.
 ls [!aeiou]* List the files with the first character not being a,e,i,o,u and the
remaining can be any other letter
 ls [a-m][c-z][4-9] ?? List all 5 character file names whose first character in range a-
m 2nd character in the range c-z, 3rd character in the range 4 to
9and 4th and 5th are any valid characters.

9 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

CREATING AND VIEWING FILES USING CAT


Cat (concatenate) command is very frequently used in Linux. It reads data from the file and gives their
content as output. It helps us to create, view, and concatenate files.

 Cat>F1 Creates a File F1 and allows us to add some contents to the file
F1. Use Ctrl+d to indicate the EOF
 Cat F1 To Display the Contents of F1
 Cat<F1 To Display the Contents of F1
 Cat F1 F2 To Display the Contents of F1 and F2
 Cat>>F1 To append the contents of File F1(old +New Contents)
 Cat F1 > F2 To create a New File F2 with the content of F1
 Cat F1 F2 > F3 To create a New File F3 with the content of F1 and F2
 Cat F1 F2 >> F3 To append the contents of F3 with the contents of F1 and F2
FILE COMPARISONS

1. Diff Command
The Linux diff command analyses a file line by line and gives an output of a list of changes made between
two files. The command diff is short for difference, which in essence gives the differences between two
files.
Diff Command Output Symbols
 The less than symbol indicates lines from the first line
 The greater than symbol indicates lines from the second line
 a - Denotes that text was added to the file
 c - Denotes that changes were made in the file
 d - Indicates that the line was deleted

10 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

Case A: Change

Assume we have two files: F1 and F2

[student@localhost p1]$ cat F1 [student@localhost p1]$ cat F2


RED RED
GREEN YELLOW
BLUE ORANGE
BLACK BLACK
WHITE WHITE
[student@localhost p1]$ diff F1 F2
2,3c2,3
< GREEN
< BLUE
---
> YELLOW
> ORANGE

The 2,3c2,3 line implies that lines 2 and 3 from the first file need to be changed in order to match lines 2
and 3 from the second text file.
Case B: Add
[student@localhost p1]$ cat F1 [student@localhost p1]$ cat F2

RED RED

BLUE GREEN

BLUE

[student@localhost p1]$ diff F1 F2

1a2

> GREEN

11 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

From the output above, 1a2 implies that after line 1 from the first file, another line needs to be added to
match line 2 from the second file.

Case C: Delete

[student@localhost p1]$ cat > F1 [student@localhost p1]$ cat > F2

RED RED

GREEN GREEN

BLUE

[student@localhost p1]$ diff F1 F2

3d2

< BLUE

Here the output 3d2 means that delete the 3rd line from the first file to sync up with the second file at line
number 2.

2. Comm Command

Comm compare two sorted files line by line and produce three-column output. Column one contains lines
unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to
both files.

12 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX MI

3. CMP Command

cmp command in Linux is used to compare the two files byte by byte and finds out whether the two files are
identical or not. If difference is found between 2 files, it reports the location of the first mismatch between 2
files.

13 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

Unit-II - Essential Linux commands: Processes in Linux, process fundamentals, connecting processes
with pipes, redirecting input/output, Background processing, managing multiple processes, process
scheduling – (at, batch), nohup command, kill, ps, who, find, sort, touch, file, file processing commands -
wc, cut, paste etc Mathematical commands - expr, factor etc. Creating and editing files with vi editor.

Processes in Linux & Process Fundamentals


A program in execution is called as a process. There are several processes running in memory at any given
moment, but only one program gets the attention of the CPU and others should wait their turn. Operating
system scheduler decides which process should get the CPU attention and when.

Linux process states


At any given moment a process in memory can be in any one of the following states:
1) Submit state: When you execute a program the scheduler submits your process to a queue called process
queue. At this instant the process is said to be in submit state.
2) Hold state: Once submitted the process waits its turn in the queue for some time. This is the hold state.
3) Ready state: As the process advances in the queue at some instant it would become the next one in the
queue to receive CPU attention. This is the ready state.
4) Run state: Finally the process gets the attention of CPU and starts execution there by attains the run state.
5) Wait state: some processes might be required to do an I/O operation. Since I/O is a slow operation the CPU
can’t lie idle till the time I/O is over. So such processes are put in wait state until their I/O is over and are
then placed in the ready state.
6) Complete state: A process whose execution comes to an end goes into complete state and is then removed
from the process queue.

PS Command
By using PS Command we can see the process that is currently running at any instant.
$ ps

PID TTY TIME COMMAND


6651 P0 0:01 sh
6661 p0 0:00 ps

1 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

➢ PID- Process ID is a unique number assigned to each process running in the memory. The PID starts
from 0 and run up to a maximum of 32767. As soon as the process terminates, its PID is released for
eventual reuse.
➢ TTY- Terminal from which the process were launched.
➢ Time- The time that has elapsed since the process was launched.
➢ Command - Name of the Process.

• Ps –a [displays all the process that are running for the other users]
• Ps -u username [displays the process of a particular user]
• Ps –t terminal id[displays all the process that are launched from a particular terminal]

Kill command
Kill command is used to Terminate a process. Some of the reasons are given below:
• The terminal has hang.
• The program, which is running, has gone in an infinite loop.
• The system performance has gone below acceptable limits because of too many processes running in
the background.
To carry out killing a process first note the PID of the process to be killed using the ps command and use
kill command.
• $ kill 5001
5001 terminated
• $ kill –9 3216
The –9 refers to sure 100% killing. The signal number 9 (sure kill) forcibly terminates a process.
• killall Netscape
It kills all instances of Netscape.

Who
Since Linux is a multiuser system ‘who’ will display the users are currently logged on.
[mca@chavara ~]$ who
mca tty1 Dec 19 13:57

2 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

mba tty2 Dec19 14:20


msw tty3 Dec19 14:24

Who am i
It tells who you are (working on the current terminal)
[mca@chavara ~]$ who am i
mca tty1 Dec 19 13:57

BACKGROUND PROCESSING
To run a process in the background, Linux provides the ampersand (&) symbol. While executing a
command, if this symbol is placed at the end of the command then the command will be executed in the
background. When you run a process in the background a number is displayed on the screen. This number is
the PID of the process that you have executed in the background.

$ Sort employee > S1 &


17653

The above example sorts the files employee in the background and stores the sorted result in the file S1.
The major limitations of background processing are:

• We need to search in the PID in the output of ps to verify whether the process is still running or
has been terminated.
• The output of a background process should, always be redirected to a file. Otherwise you would
get a garbled screen showing the output of the background process along with whatever you are
doing in the foreground.
• With too many processes running in the background the overall system performance is likely to
degrade.
• If you log out while some of your processes are running in the background all these processes
would be abandoned halfway through.
The nohup command
Nohup stands for no hang ups. This command ensures that the processes that we have executed should not
die even when we log out. Using this command we can submit the time consuming commands in the

3 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

background. If we log out from the terminal it automatically works on the background and performs the
desired task.
MANAGING MULTIPLE PROCESSES/PROCESS SCHEDULING

Linux provides tools to permit scheduling of processes as per the user /system requirements. Once the user-
has submitted a process to, Linux directing it to execute the process at a specified time and date in future,
Linux will execute that process at that specified time. Cron daemon is a system process responsible for
scheduling of other processes. During booting of Linux cron automatically started and its checks any
scheduled job is available for it to execute, and if it is, it executes the job.

Commands for Process Scheduling

1. at

The ‘at’ command schedules a command, to be run once at a particular time. The ‘at’ command can be
anything from a simple reminder message, to a complex script.

You start by running the ‘at’ command at the command line, passing it the scheduled time as the option. It
then places you at a special prompt, where you can type in the command (or series of commands) to be run at
the scheduled time. When you're done, press Control-D on a new line, and your command will be placed in
the queue.

Example

[root@localhost ~]# at now + 1 minutes

at> echo "hi">/dev/pts/0

at> <EOT>

job 4 at 2019-11-27 09:25

4 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

On pressing ‘Ctrl+d’ the ‘at’ command displayed the job-id and the date and time we requested for the
execution. Once submitted this way, the message would be echoed on our terminal (/dev/pts/0) 1 minute
after the current time.

There are two options available with the ‘at’ command which permit us to view the list of jobs submitted
using at and to remove any unwanted jobs from this job queue. These options are -l for listing jobs and -r for
removing jobs. While removing a submitted job its job-id should be mentioned.

$ at –r 4 Would remove the job ‘4’ from the job queue.

$ at –l Lists all the process submitted using at command

Following are some of the specifications that can be used with at:

• $ at 9:15 am Mar 24
• $ at now + 10 minutes
• $ at now + 1 day
• $ at 7 pm Thursday next week

2. The batch command


Using batch command the system decides the best time for executing our commands. Since the time of
execution of our commands is left for the system to decide we don't specify the time while executing the
batch command.
$ batch
sort employee > F1
Ctrld
Job 5 at Fri Jun 14 17:00:00 IST 2019
3. The crontab command
Though at and batch are powerful tools for scheduling processes, both suffer from an obvious limitation,

once jobs submitted using these commands have been executed, the jobs will have to be rescheduled if they

are to be carried out again.

5 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

Crontab is used to execute the commands or programs on a regular schedule including backup, recovery,

copying or any other activity. crontab can carry out a submitted job every day for years together, without

needing any prompting from us. The jobs can be carried out on a regular basis using the crontab command

as shown below:

$ crontab cmdfile

Minute Hour Day of Month Month of year Day of week Command

Using this format let us create our F1


$ cat > F1

30 10 15 8 * echo "Happy Independence Day" >/dev/pts/0


Ctrl d
$

The above command will echo the message at 10:30 am on 15 day of August month.’*’ indicates any day.

REDIRECTING INPUT/OUTPUT
In all Operating systems the standard input device is keyboard and standard output device is
monitor (display screen). Linux allow you to change the standard input and output temporarily by using
redirection. Redirection is the process of changing the assignment of standard input device, standard output
device.
Output Redirection
Most command line programs that display their results do so by sending their results to a facility called
standard output. By default, standard output directs its contents to the display. To redirect standard output to
a file, the ">" character is used like this:
$ ls > file_list.txt

In this example, the ls command is executed and the results are written in a file named file_list.txt. Since the
output of ls was redirected to the file, no results appear on the display.

6 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

Each time the command above is repeated, file_list.txt is overwritten from the beginning with the output of
the command ls. To have the new results appended to the file instead, we use ">>" like this:

$ls >> file_list.txt

Input Redirection

Many commands can accept input from a facility called standard input. By default, standard input gets its
contents from the keyboard. To redirect standard input from a file instead of the keyboard, the "<" character
is used like this:
$ sort < file_list.txt

In the example above, we used the sort command to process the contents of file_list.txt. The results are
output on the display since the standard output was not redirected. We could redirect standard output to
another file like this:
$ sort < file_list.txt > sorted_file_list.txt
Connecting processes with pipes

Piping facility ( | ) connects more than 1 command. By using piping facility the output of one
command will become the input of another command.
• $ ls | wc -l
Here the output of ls becomes the input to wc which counts the number of lines it receives as input and
displays this count on the screen.
• $ ls | wc –l > countfile
Instead of displaying this count, if we want to store the count value in a file, use the output redirection.
File Processing Commands

1. wc
wc stands for word count. As the name implies, it is mainly used for counting purpose. It is used to
find out number of lines, number of words count and number of characters in one or more files.
Syntax:

7 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

wc [OPTION]... [FILE]...

Example
$ cat F1
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh

• $ wc F1
5 7 63 F1 Displays the count of Lines, Words and Characters in the file F1
• $ wc -l F1
5 F1 Displays the number of Lines in F1
• $ wc -W F1
7 F1 Displays the number of Words in F1
• $ wc -C F1
63 F1 Displays the number of Characters in F1

2. cut

Cut command is used to extract specific columns from a file or extract the output of some commands.

$ cat F1

1 CHEMISTRY 25

2 ENGLISH 30

The file F1 consists of 3 fields separated by a Tab Space

• $ cut –f 2,3 F1 displays the 2nd and 3rd Field from file F1
• $ cut –f 1-3 F1 displays the 1st ,2nd and 3rd Field from file F1

8 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

• $ cut –c 1-3 F1 displays the 1st ,2nd and 3rd character from file F1
• $ cut –d ‘:’ –f 2,3 F1 displays the 2nd and 3rd Field from file F1- When fields are
separated by characters other than the default tab use –d option which
allows us to set the delimiter.

3. Paste command

This command concatenates the contents of the specified files into a single file vertically. Paste command
merges the columns
$ cat F1

CHEMISTRY

ENGLISH

$ cat F2

25

30

• Paste F1 F2 Combines the data vertically of file F1 and F2

CHEMISTRY 25

ENGLISH 30

• Paste –d ‘:” F1 F2 Combines the data vertically of file F1 and F2 and the
delimiter is ‘:’. The default delimiter is Tab Space.

4. Sort command

It can be used for sorting the contents of a file. It can merge multiple sorted files and store the result in the
specified output file.

9 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

• $ sort myfile

This would the sort the contents of myfile

• $ sort –r myfile

This would the sort the contents of myfile in the reverse order

• $ sort –k 2 myfile

This would the sort the contents of myfile based on the 2nd field of myfile

TOUCH COMMAND

Touch command: It is used to create a file without any content. The file created using touch command is
empty. This command can be used when the user doesn’t have data to store at the time of file creation.

• $ touch F1 Created an empty File F1


• $ touch F2 F3 Created many empty Files

MATHEMATICAL COMMANDS
1. Factor
Print the prime factors of each NUMBERs. If no arguments are specified on the command line,
they are read from standard input.
• $ factor 2
2: 2
• $ factor 12
12: 2 2 3
• $ factor 13
13: 13
• $ factor15
15: 3 5

10 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

2. expr
It is used to perform arithmetic operations on integers.
+ Addition
- Subtraction
* Multiplication
/ Division (decimal portion will be truncated, division is done only on integers,
gives the quotient only)
% Remainder of division (modulus operator)
A white space must be used on either side of an operator. The * operator has to be escaped to
prevent the shell from interpreting it as the filename meta character. So use \ before the *
character.
[mca@chavara ~]$ x=5
[mca@chavara ~]$ y=2
[mca@chavara ~]$ expr $x + $y
7
3. bc [Binary Caclualator]
Binary calaculator is used for real number calculations, Number Conversion etc.
[mca@chavara ~]$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with
ABSOLUTELY NO WARRANTY. For details type `warranty'.
10 + 20  arithmetic expression
30  result is displayed on the screen
Press ctrl d to end work

[mca@chavara ~]$ bc
ibase = 2  set ibase to binary(2) ibase means input base
101  type the input in binary number
5  result in decimal
[mca@chavara ~]$ bc
obase = 2  set obase to binary obase means output base

11 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

5  type the input in decimal number


101  result in binary.

CREATING AND EDITING FILES WITH VI EDITOR.

A text editor is a program that enables you to create and modify text files. Typically, a text editor
provides a screen with a fixed line length and line numbers. You can type text line by line, navigate
through the documents by using different commands, and save the document. Typically, a text editor
enables you to perform the following functions: Create files, Open files Copy text, Search for text
etc.
Editors Available with Linux
• vi • emacs • red • pico
• vim • ed • joe

THE VI EDITOR
The visual editor, popularly known as the vi editor, is one of the most widely used Linux -based text
editors. It offers a compact interface and enables you to control the system by using the keyboard.
The vi editor is commonly used to enter and edit source code and write short notes, such as e-mail
messages.
It is a screen oriented text editor developed by Bill Joy in 1976. Commands are entered through
keyboard. We can also use mouse support and a GUI version with scrollbars and menus can be
activated.
Running vi
To run vi and create a new file, simply run the command 'vi' from any shell prompt:
$ vi
To create a File and giving a name to that file use
$ vi F1
To load an existing text file into vi, run the command 'vi [filename]', from the shell prompt:
$ vi F1
Your file will be loaded into vi, and the cursor will be placed at the beginning of the first line. Note
that an empty line is shown as a tilde (~).

12 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-II

Modes of operation
1) Command mode: To switch to command mode Press ESC key. Here all keys pressed by the user
are interpreted as commands. The keys that are hit are not displayed on the screen.
2) Insert mode: It is activated by pressing ‘i’. It allows insertion of new text, editing and replacements
of text. In insert mode the characters we type are added to the file. It is also known as input text mode.
3) The ex command mode: It permits us to give commands at the command line. The bottom line of
the vi screen is called the command line.vi uses command line to display messages and commands. All
commands entered in this mode are displayed in the command line. It is so called because commands given
in this mode are compatible with the commands of the ex editor

The cursor keys

To move the cursor around the screen, you must be in command mode.

h - Cursor left
j - Cursor down
k - Cursor up
l - Cursor right

Saving files and quitting vi

Command Description
:e file edit file (save current file with :w first)
:w save (write out) the file being edited
:w file save as file
:w! file save as an existing file
:q quit vi
:wq save the file and quit vi
:x save the file if it has changed and quit vi
:q! quit vi without saving changes

13 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

Shell programming - Basics of shell programming, various types of shell available in Linux, comparisons
between various shells, shell programming in bash. Conditional and looping statements, case statement,
parameter passing and arguments, Shell variables, system shell variables, shell keywords, Creating Shell
programs for automating system tasks

Basics of shell programming.


A Shell Program or a Shell Script is a block of code which consists of shell commands. It is written using a
text editor like vi or joe editor.
Features of shell program
• Shell program has the functionality of input/output, iteration, logical decision making, file creation
,deletion etc.
• Shell program may consist of one or more shell commands
• It can be created using any text editor of choice – vi,joe etc.
• It is format free. It means that blank lines, indentation and white spaces can be used.
• Own commands can be created using shell programming.
• It helps in performing repeatedly occurring tasks.
• A shell program saves a lot of time.
• It can be used for automate routine tasks.
• Easy to write debugging code into a script to detect and fix bugs

When to use shell scripts


Shell programs can be used for a variety of tasks some of which are mentioned below:
• Customizing your work environment. For example every time you log in if you want to see the
current date, a welcome message and the list of users who have logged in you can write a shell script
for the same.
• Automating your daily tasks. For example, you may want to back up all your programs at the end of
the day. This can be done using a shell script.
• Executing important system procedures like shutting down the system, formatting a disk, creating a
file system on it, mounting the file system, letting the users the floppy and finally unmounting the
disk.

1 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

SHELLS AVAILABLE IN LINUX


A shell is a program that provides an interface between a user and an operating system (OS) kernel. An OS
starts a shell for each user when the user logs in or opens a terminal or console window. All the shells are
located at/bin directory. Various shells available in Linux are as follows:
BOURNE SHELL
• The BOURNE SHELL was developed at AT& T Bell Labs.
• The Bourne shell written by Steve Bourne.
• It is distributed with all Linux systems and the most widely used shell.
• The executable file name for this shell is sh.
• It is the preferred shell for shell programming because of its compactness and speed.
• A Bourne shell drawback is that it lacks features for interactive use, such as the ability to
recall previous commands (history).
• The Bourne shell also lacks built-in arithmetic and logical expression handling.
C SHELL
• It was developed by William Joy at the University of California at Berkeley
• C SHELL provides a programming interface similar to the C programming language.
• The executable file name for this shell is csh.
• Incorporated features for interactive use, such as aliases and command history.
• Includes convenient programming features, such as built-in arithmetic and a C-like expression
syntax.

KORN SHELL
• Was written by David Korn at AT&T Bell Labs
• It combines the features of Both Bourne shell and C Shell.
• The executable file name for this shell is ksh.
• Has an interactive feature comparable to those in the C shell.
• Includes convenient programming features like built-in arithmetic and C-like arrays, functions,
and string-manipulation facilities.
• Is faster than the C shell.
• Runs scripts written for the Bourne shell.

2 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

RESTRICTED SHELL
• Restricted shell provides limited access on the operating system to a user.
• The restricted shell is typically used for guest users who only need limited rights and permissions.
• You can use this shell to restrict the users of the operating system to a limited environment.
BASH SHELL
• It is an enhancement on the Bourne Shell
• Bash stands for Bourne Again Shell.
• The executable file name for this shell is sh.
• Bash is product of Free Software foundation’s GNU project.
• It stores all of the commands that you use in a session and also in the previous shell.
• Incorporates useful features from the Korn and C shells.
• Have arrow keys that are automatically mapped for command recall and editing.
Tcsh SHELL
• Tcsh stands for Tom’s C shell
• It is an enhancement of the C shell.
• It is also known as the TC shell.
• The executable file name for this shell is tcsh.
A SHELL
• It was developed by Kenneth Almquist of the University of Berkeley.
• The A shell is suitable for computers that have limited memory.
• The executable file name for the A shell is ash.
Z SHELL
• It offers the features of Tcsh and Korn shells.
• It also provides a large number of utilities and extensive documentation.
• The executable file name for the Z shell is zsh.

3 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

COMPARISON OF SHELLS

Feature Bourne Korn C Tcsh Bash


Background processing Yes Yes Yes Yes Yes
Command history No Yes Yes Yes Yes
I/O redirection Yes Yes Yes Yes Yes
Shell scripts Yes Yes Yes Yes Yes
Command alias No Yes Yes Yes Yes
File name completion No Yes No Yes Yes
Command completion No No No Yes Yes
Command line editing No Yes No Yes Yes
Job control No Yes Yes Yes Yes

Shell Programming in BASH


Writing and Executing the Shell Scripts
Following steps are required to write shell script:
1) Use any text editor like vi
2) Save and exit the editor file. Press :wq
3) To execute the shell script use sh programname
Inserting Comments
A word or line beginning with # causes that word and all remaining characters on that line to be ignored.
These lines aren't statements for the bash to execute. In fact, the bash totally ignores them. These notes are
called comments.
Shell Keywords
Keywords are the words whose meaning has already been explained to the shell. The keywords cannot
be used as variable names because if we do so we are trying to assign a new meaning to the keyword,
which is not allowed by the shell. The keywords are called reserved words. Given below are list
keywords used in Bourne Shell:

4 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

echo, read, set, unset, readonly, shift, export, if, else, fi, while, do, done, for, until, case, esac, break,
continue, exit, return, trap, wait, eval, exec, ulimit, umask etc
Shell Variables
Variables in Linux are of 2 Types
1. Linux defined/System Variables/Environment Variables
These are the standard variables which are always accessible. The shell provides the values of these
variables. These variables are usually used by the system itself and govern the environment we are
working. If we needed we can change the values of these variables as per our preferences and
customize the system environment.

• USER - The current logged in user.


• HOME - The home directory of the current user.
• EDITOR - The default file editor to be used. This is the editor that will be used when you
type edit in your terminal.
• SHELL - The path of the current user’s shell, such as bash or zsh.
• LOGNAME - The name of the current user.
• PATH - A list of directories to be searched when executing commands. When you run a
command the system will search those directories in this order and use the first found
executable.
• LANG - The current locales settings.
• TERM - The current terminal emulation.
• MAIL - Location of where the current user’s mail is stored.

Example
[student@localhost ~]$ printenv HOME
/home/student
[student@localhost ~]$ printenv SHELL
/bin/bash

5 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

2. User defined Variables


These are the variables created by the user It provides the ability to store and manipulate information
within a shell program. The variables you use are completely under your control. We can create and
destroy any number of variables as needed to solve the problem at hand.

Creating user defined Variables


In bash shell we do not declare variables explicitly. Variables can be created simply by assigning a
value.
Syntax <Variable Name>=<Value>
Note that while assigning values to variables using the assignment operator ‘ = ‘ , there should be no
spaces on either side of =. If you leave space the shell will try to interpret the value being assigned as
a command to be executed.
Example
name="red hat"
address=USA
price=100
Referencing Variables
The $ symbol is used to refer to the contents of a variable.
variable1=${varaible2}
Example
newprice=$price
Echo Command
We can use echo commands to display messages on the screen
Echo “ This is an example of echo command”
echo $name
echo $address
echo $price
Reading a value into a variable
You can enter the value into a variable during the execution of a shell script by using the read
command.
read name

6 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

On execution the read command waits for you to enter a value for the variable. When you press the <Enter>
key the value is read and assigned it to the variable.
echo "Enter the Phone Number"
read phno
echo $phno
Command Substitution
Using command substitution we can combine more than one command.
echo "The date is `date`"
The date is Mon Feb 10 23:21:52 PST 2020
The command date is enclosed in single backward quotation marks. While executing the command the shell
first replaces the enclosed command with the output of the command. Then the shell executes the entire
command.

Arithmetic in Shell Script


By using expr command we can perform arithmetic operations in shell scripts.
expr 4 + 5
The above command will display the output 9 on the screen. Notice that we need to add a space on either
side of + operator.
We can use variables in the expr command.
a=5
b=4
expr $a + $b
The expr command doses not support decimal operations. To carry out operations on decimal numbers use
bc command.
x=2.3
y=1.5
z=`echo $x + $y |bc`
echo $z
Arithmetic Expansion
To calculate the value of an expression you can enclose the expression in $ ( ( ….. ) )
Example:

7 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

echo $ ( ( 45 + 34 ) )
79
a=12
b=10
echo $ ( ( a + b ) )
22
Conditional Execution in Shell Script
A shell script might contain a list of statements. To execute statements conditionally we can use IF construct
and case construct.
I. IF Construct
If we want to check a specific condition and execute commands based on whether the status of the
condition is true or false. In such cases we can use IF Construct.
The IF construct evaluates a given condition expression. If the result is true, then the statements
following the IF construct is executed. If the result is false, the statements are skipped and the
control moves to the else statement. Here FI is used to indicate the end of the construct.
read x
read y
if [ $x -ge $y ]
then
echo " X is greater"
else
echo " Y is greater"
fi
IF…ELIF Construct
In this construct the ELIF specifies the ELSE IF Condition. The ELIF statement is executed only
when the IF condition is false.
read mark
if [ $mark -lt $75 ]
then
echo " C+ "
elif [ $mark -lt 90 ]

8 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

then
echo " B+ "
else
echo " A+ "
fi

Numerical Tests
Operator Meaning

-gt greater than


-lt less than
-ge greater than or
-le less than or equal
-ne not equal to
-eq equal to

String Test Operators


Condition Meaning
string 1 = string2 True if the strings are same
String 1 ! =string2 True if the strings are different
-n string True if the length of string is greater than 0
-z string True if the length of the string is zero
string True if the string is not a null string
File Test Operators

9 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

II. Case…Esac Construct


The Case Esac Construct is often used instead of IF…ELIF Construct when you need to check for
multiple and complex conditions.
The Case…Esac Construct evaluates a value of the variable and compares it with each value
specified by the user. When the value of the variable matches one of the specified values, the set of
commands written under that value is executed. A pair of semicolon is to delimit the commands of a
value from the commands of other values. The default value is specified by using the *) instead of a
Value.
echo "Enter an RGB COLOR"
read color
case $color in
R)
echo "RED"
;;
G)
echo "GREEN"
;;
B)
echo "BLUE"
;;
*)
echo "Invalid Color"
esac

Iteration/Looping in Shell Script


Iteration refers to the repetition of a sequence of instructions. Iteration is also known as looping. To perform
iteration in shell scripts we need t specify a set of initial conditions, the termination condition and the
commands that needed to be executed repeatedly.
The Linux Operating system provides the following iteration constructs.
1. While
2. Until

10 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

3. For

1. While Construct

In the while iteration construct, the commands to be executed are specified within the do and done
keywords. The do and done keywords are used to delimit commands in an iteration construct. The syntax is:
While<Condition> i=1
Do while [ $i -le 5 ]
<Commands> do
Done echo $i
((i=$i+1))
done

In the above syntax, the commands within the do and done keywords are executed as long as the condition
evaluates to true.
2. Until Construct
until<Condition> i=1
Do until [ $i -gt 5 ]
<Commands> do
Done echo $i
((i=$i+1))
done
If the condition becomes true the until loop will terminates.
If the condition becomes false the while loop will terminates.

3. For Construct
The for loop accepts a list of variables or expressions as input and executes the commands within do and
done, based on the value of the variable or expression. The syntax for the for construct is given below.

11 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-III

for((expression1; expression2; expression3)) for((i=1;i<=5;i++))


Do do
<Commands> echo $i
Done done
In the above syntax
Expression 1 is evaluated once before the loop is executed.
Expression 2 is evaluated before each iteration. If the expression2 evaluates to false, the for loop
terminates.
Expression 3 is evaluated each time the loop iterates.
Parameter Handling in Shell Script
Parameters are used to pass arguments from the command line to a shell script. A parameter is any word or
a string, such as file name that is specified along with a command or a file name at the shell prompt. In a
shell script a parameter is referred to as an argument. When we are executing a shell script bash<Program
Name> argument list, the shell places each word on the command line in special variables $0 through $9.
Example CP Dir1 Dir2
In the above example $0 variable contains CP; the $1 variable contains Dir1 and $2 Contains Dir2.
In Linux operating system, the shell creates a maximum of 9 variables apart from $0. The $0 is the
command in the command line.

$* variable contains the entire string [Above example $* contains Dir1 and Dir2]
$# variable contains the number of arguments specified in the command [Above example $# contains 2
which means 2 arguments are passed as command line arguments]

12 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

Unit-4 System administration - Common administrative tasks, identifying administrative files


configuration and log files, Role of system administrator, Managing user accounts-adding & deleting users,
changing permissions and ownerships, Creating and managing groups, modifying group attributes,
Temporary disabling of users accounts, creating and mounting file system, checking and monitoring system
performance - file security & Permissions, becoming super user using su. Getting system information with
uname, host name, disk partitions & sizes, users, kernel, installing and removing packages with rpm
command.

ROLE OF SYSTEM ADMINISTRATOR/COMMON ADMINISTRATIVE TASKS


The system administrator is responsible for ensuring that the Linux system provides a reasonable service to
its users. This involves a variety of activities;
 Adding new users to the system and configuring their home directories and basic privileges.
 Creating Groups and adding various users to groups.
 Setting various privileges to the user.
 To maintain smooth running of system.
 Installing any new software, including applications, new versions of the operating system, or bug
fixes.
 To check that the peripherals are working properly.
 To manage hardware and arrange timely repair of hardware in case of any failure.
 To create file systems as per the organizational requirements.
 To formulate and manage the back up and recover policy to counter any crisis or loss of data.
 Monitoring the usage of the file system.
 Responding to problems from users, attempting to track down bugs
 To implement security policies for use of the computer system and network.
 Ensuring the smooth operation of any network services, such as electronic mail or remote access to
other machines
IDENTIFYING ADMINISTRATIVE FILES -CONFIGURATION AND LOG FILES
Linux files are grouped according to their functionality and usage, so there are separate directories for
configuration and log files.

1 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

Configuration files: The directory for such file is the /etc directory. Most of the configuration files
resides in the /etc directory. Some of them are as follows:
/etc/passwd contains user password and login configurations
/etc/shadow contains user encrypted passwords.
/etc/shells shells installed on the system that users can use.
/etc/group Configuration file for the user groups.
/etc/filesystems Known file systems
/etc/fstab Lists partitions and their mount points.
/etc/inittab Information for booting.
/etc/ftp* Configuration of the ftp-server
/etc/mail Behavior of the mail server
/etc/ printcap Printer Configuration Files

Log files: The directory for such files is the /var directory. We can use log files to help tracking the
different problems.
BootLog-contains messages indicating which systems services have started & shut down successfully
and which have failed to start and stop.
CronLog -Contains message from Cron, a daemon that periodically runs scheduled jobs like backups.

Managing User Accounts

I. Adding users

In Linux, ‘useradd‘ command is used for adding/creating user accounts in Linux.


1. How to Add a New User in Linux-To add/create a new user, all you’ve to follow the command
‘useradd‘ or ‘adduser‘ with ‘username’. The ‘username’ is a user login name that is used by user to
login into the system. Only one user can be added and that username must be unique (different from
other username already exists on the system).
For example, to add a new user called ‘S4BCA‘, use the following command.
[root@tecmint ~]# useradd S4BCA
If it is not working properly use the complete path /usr/sbin/useradd S4BCA

2 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

When we add a new user in Linux with ‘useradd‘ command it gets created in locked state and to unlock that
user account, we need to set a password for that account with ‘passwd‘ command.
[root@tecmint ~]# passwd S4BCA
Changing password for user S4BCA.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
Once a new user created, it’s entry automatically added to the ‘/etc/passwd‘ file.

2. Create a User with Different Home Directory


By default ‘useradd‘command creates a user’s home directory under /home directory with username.
However, this action can be changed by using ‘-d‘ option along with the location of new home directory
(i.e. /data/projects). For example, the following command will create a user ‘S4BCA‘ with a home directory
‘/data/projects‘.
[root@tecmint ~]# useradd -d /data/projects S4BCA

3. Create a User with Specific User ID


In Linux, every user has its own UID (Unique Identification Number). By default, whenever we create a
new user accounts in Linux, it assigns userid 500, 501, 502 and so on…But, we can create user’s with
custom userid with ‘-u‘ option. For example, the following command will create a user ‘S4BCA‘ with
custom userid ‘999‘.
[root@tecmint ~]# useradd -u 999 S4BCA
You can verify the user’s UID, using the id command:
id -u S4BCA
1500
4. Create a User with Specific Group ID/Group Name
There are two types of groups in Linux operating systems Primary group and Secondary or supplementary
group. Each user can belong to exactly one primary group and zero or more secondary groups.
 Primary group is created at the time when a new user is created. If we are creating a new user a
primary group is created with same Group Id (GID) as UID and Same Group Name (GN) as User
Name.

3 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

 Secondary Groups are used to organize and administrate user accounts. Example All the users
having same privilege/ All the users of a Project can be added to a Secondary group.

The main purpose of groups is to define a set of privileges such as reading, writing, or executing permission
for a given resource that can be shared among the users within the group.
When creating a new user the default behavior of the useradd command is to create a group with the same
name as the username, and same GID as UID.
We can create users with specific group[Secondary Group] with -g option. We can specify either group
Name or Group ID, Here in this example, we are adding a user ‘S4BCA‘ with a specific GID with ‘-g‘
option.
[root@tecmint ~]# useradd -g 500 S4BCA
In this example we are adding the user S4BCA to the secondary group ‘Projects’
[root@tecmint ~]# useradd –g Projects S4BCA
5. Add a User to Multiple Groups/Secondary Groups
The ‘-G‘option is used to add a user to multiple groups. Each group name is separated by a comma, with no
intervening spaces. Here in this example, we are adding a user ‘S4BCAt‘into 3 groups
nameily admins, webadmin and developer.
[root@tecmint ~]# useradd -G admins,webadmin,developers S4BCA
6. Create a User with Account Expiry Date
By default, when we add user’s with ‘useradd‘ command user account never get expires i.e their expiry date
is set to 0 (means never expired).
However, we can set the expiry date using ‘-e‘option, that sets date in YYYY-MM-DD format. This is
helpful for creating temporary accounts for a specific period of time.
Here in this example, we create a user ‘S4BCA‘ with account expiry date i.e. 27th April 2014 in YYYY-
MM-DD format.
[root@tecmint ~]# useradd -e 2014-03-27 S4BCA
7. Create a User with Password Expiry Date
The ‘-f‘argument is used to define the number of days after a password expires. A value of 0 inactive the
user account as soon as the password has expired. By default, the password expiry value set to -1 means
never expire.

4 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

Here in this example, we will set a account password expiry date i.e. 45 days on a user ‘S4BCA’ using ‘-
f‘option..
[root@tecmint ~]# useradd -f 45 S4BCA

II. Modifying User Accounts

The command ‘usermod‘ is used to modify or change any attributes of a already created user. After creating
user accounts, in some scenarios where we need to change the attributes of an existing user such as, change
user’s home directory, login name, login shell, password expiry date, etc, where in such case ‘usermod’
command is used.
 -d = To modify the directory for any existing user account.
# usermod -d /var/www/ S4BCA
 -e = Using this option we can make the account expiry in specific period.
# usermod -e 2014-11-01 S4BCA
 -g = Change the primary group for a User.
# usermod -g Projects S4BCA
 -G = To modify supplementary groups.
# usermod -G PHPPROJECTS S4BCA
 -l = To change the login name from S4BCA to S4BCAB. To change any existing user login name,
we can use ‘-l‘ (new login) option. In the example below, we changing login name S4BCA to
S4BCAB..
# usermod -l S4BCAB S4BCA
 -L = To lock the user account. This will lock the password so we can’t use the account. To
Lock any system user account, we can use ‘-L‘ (lock) option, After the account is locked we
can’t login by using the password
# usermod -L S4BCA
 -U = To unlock the user accounts. This will remove the password lock and allow us to use
the user account.
# usermod -U S4BCA

5 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

 -s = Create a Specified shell for new accounts. For example, the user ‘S4BCA‘ has
the /bin/bash shell by default, now I want to change it to /bin/sh.
# usermod -s /bin/sh S4BCA
III. Deleting User Accounts

userdel command in Linux system is used to delete a user account and related files. This command basically
modifies the system account files, deleting all the entries which refer to the username. The userdel command
takes a single argument which is the login name of the account to delete. Use –r option to delete user’s
home directory and all files in it.
Examples
$ userdel S4BCA delete user account with login name S4BCA
$ userdel –r user1 To delete S4BCA’s home directory along with user account.

Lock (Disable) User Account in Linux

Linux systems allow you to lock or disable access to a particular user account without changing anything
from the account.
Linux distributions use /etc/shadow file to store the encrypted user passwords. A user account can be
temporarily disabled or permanently removed.

1. Lock (Temporary disable) user account


We can disable or lock a user account temporarily by just putting an asterisk "*" or “!” at the beginning of
the second field in the file /etc/shadow. This means that "*" won’t permit login for this account. Whenever
you want to enable the account, just erase the asterisk and the user account is back in operation with its old
password.
2. Using passwd command
Passwd command can be used to lock or disable the user account. -l option will disable the user accounts
# passwd Tom –l
If you want enable the account just unlock it using –u option as follows:
# passwd Tom -u

6 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

Managing Groups

In Linux, groups are used to organize and administer user accounts. The primary purpose of groups is to
define a set of privileges such as reading, writing, or executing permission for a given resource that can be
shared among the users within the group.
In a scenario where there are many users, there might be some privileges that some users have and some
don’t, and it becomes difficult to manage all the permissions at the individual user level. So using groups,
we can group together a number of users, and set privileges and permissions for the entire group.
When you add a group to the system, the system places the group’s name in the /etc/group file and gives it a
group ID number.
I. Creating Groups

 To create a new group named BCA you would run:


groupadd BCA
The command adds an entry for the new group to the /etc/group and /etc/gshadow files. Once the group is
created, you can start adding users to the group.
 To create a Group with a specific GID
When a new group is created, the system assigns the next available GID from the range of group IDs.
To create a new group named BCA with a specific groupid 1000 we should use the –g option
Example: groupadd -9 1000 BCA

II. Modifying a Group


You can change the attributes of the group with the groupmod command.
 Change the Groupid
Enter groupmod –g with the new ID number and the group name.
Example groupmod –g 1050 BCA
This will change the BCA group id to 1050
 Change the Group Name
To change the name of a group use the –n option. Enter groupmod –n with the new name of the group,
followed by current name.
Example groupmod –n BCA2021 BCA
This will change the group name to BCA2021

7 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

III. Deleting a Group


You can delete a group with the groupdel command. To delete a group BCA use the syntax:
$ groupdel BCA
Change the File Group Ownership
By default if a user created a File, the group of the file will belongs to the group of the file owner. To
change the group ownership of a file or directory invoke the chgrp command followed by the new group
name and the target file as arguments.
For example, to change the group of the file F1 to project you would run:
chgrp project F1
MOUNTING A FILE SYSTEM
The meaning of Mounting is to attach the newly created File System to the currently
accessible File System in Linux. A device for mounting can be a partition (a logically independent
section) on a HDD, Floppy Disk, CDROM, and USB Key Drive, Tape Drive or any other external media.

To get the access of files on a storage device user must first direct the Linux where to
mount the device known as Mount Point. For example, to get the access of files on a CDROM, user must
direct the Linux to make the file system on the CDROM appear in some directory, typically /mnt/cdrom
(which already exists for this very purpose).

Mount Point refers to the empty directory in the currently available file system with
which a newly created or additional file system is mounted. The /mnt directory already exists in Linux
by default on all Unix like systems. This directory with its subdirectories like /mnt/floppy , /mnt/usb are
intended specifically to be used as mount points for removable media such as CDROMS, USB key drives
and floppy disks.

Mounting can be done by the root user by using the mount command with the name of the
device to be mounted and its mounting point / destination.

For eg: to mount the second partition on the first HDD , which is designated by /dev/hda2
, using a directory named / BCA as the mount point we use - $ mount /dev/hda2 /BCA.

We can remove the connection between the mounted device and the rest of the file
system. This process is called Unmounting. It is done by executing the umount command, followed by
the name of the device to be detached or unlinked and its mount point. For eg : to umount the second
partition from the root file system We use the command:

8 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

- $ unmount /dev/hda2 /BCA.

SUPER USER/ SU LOGIN AS SUPER USER /ROOT /SWITCH USER


Root is the administrator or Super User in Linux. And Super User can perform any activity in Linux. To
login as root /super user , enter the su command .
$ su
Password:
After entering the valid password of root, we will be logged in as root or Super User. After this we will
be able to perform any action on Linux OS.
$ su BCA
Password :
Here SU will act as Switch user to login to the user BCA

GETTING SYSTEM INFORMATION WITH UNAME, HOST NAME

Hostname

A hostname is a name which is given to a computer and that is attached to the network. Its main purpose
is to uniquely identify over a network.

 To display the host name

[root@sccs student]# hostname

sccs
 Display the IP address of the system
[root@sccs student]# hostname -i
172.25.0.15
 Set the hostname of the system to MGU
[root@sccs student]# hostname MGU
[root@sccs student]# hostname
MGU
Uname

The command ‘uname‘ displays the information about the system.

9 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

 -a option: It prints all the system information in the following order: Kernel name, network node
hostname, kernel release date, kernel version, machine hardware name, hardware platform,
operating system

[root@sccs student]# uname -a

Linux MGU 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:02 EDT 2007 i686 i686 i386 GNU/Linux

 -s option: It prints the kernel name.

 -n option: It prints the hostname of the network node(current computer).

 -r option: It prints the kernel release date.

 -v option: It prints the version of the current kernel.

 -m option: It prints the machine hardware name.

 -p option: It prints the type of the processor.


 -o option: It prints the name of the operating system.

Redhat Packet Manager/ RPM


RPM command is used for installing, uninstalling, upgrading, querying, listing, and checking RPM
packages on your Linux system.

RPM stands for Red Hat Package Manager.


With root privilege, you can use the rpm command with appropriate options to manage the RPM software
packages.
RPM filename has packagename, version, release and architecture name.
For example, In the MySQL-client-3.23.57-1.i386.rpm file:
 MySQL-client – Package Name

 3.23.57 – Version

 1 – Release

 i386 – Architecture

10 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

When you install a RPM, it checks whether your system is suitable for the software the RPM package
contains, figures out where to install the files located inside the rpm package, installs them on your system,
and adds that piece of software into its database of installed RPM packages.
 Installing a RPM package Using rpm -ivh
The following rpm command installs Mysql client package.

# rpm -ivh MySQL-client-3.23.57-1.i386.rpm

Preparing... ########################################### [100%]

1:MySQL-client ########################################### [100%]

 Query all the RPM Packages using rpm -qa


You can use rpm command to query all the packages installed in your system. Here –q is for the query
operation and –a is for all the installed packages

# rpm -qa

cdrecord-2.01-10.7.el5

bluez-libs-3.7-1.1

setarch-2.0-1.1

 Query a Particular RPM Package using rpm -q


After installation of a package to check the installation, you can query a particular package and verify as
shown below.

# rpm -q MySQL-client

MySQL-client-3.23.57-1

# rpm -q MySQL

11 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

package MySQL is not installed

 Upgrading a RPM Package using rpm -Uvh


Upgrading a package is similar to installing one, but RPM automatically un-installs existing versions of the
package before installing the new one. If an old version of the package is not found, the upgrade option will
install it.

# rpm -Uvh MySQL-client-3.23.57-1.i386.rpm

Preparing... ########################################### [100%]

1:MySQL-client ###########################################

 Uninstalling a RPM Package using rpm -e


To remove an installed rpm package using -e as shown below. After uninstallation, you can query using rpm
-qa and verify the uninstallation.

# rpm -e MySQL-client

File Access Permissions FAP


FAP helps to secure files and folders. File access permissions refer to the permissions associated with a
file or directory with the respect of the following:
 File Owner
 Group Owner
 Other Users
The Permissions that can be granted or revoked are symbolically represented by the letters r,w,x .
The Permissions for a file or a directory are:
Viewing File Access Permissions

12 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

We can view the file access permissions by using the ls -l command.


example:
[steve@localhost ~]$ ls -l file1
-rw-rw-r-- 1 steve steve 52 Jun 20 15:14 file1
The above command displays the FAP of file1. We can view the file access permissions of all files and
directories in the current directory we can use ls -l command without a file or a directory name.
The Permissions for a file or a directory are:
Access Denoted by Action Permitted on The File Action Permitted on The Directory
Type

r Read Allows you to display, copy and Allows you to list the contents of
Permission compile the file the directory

w Write Allows you to edit, rename and Allows you to create directories and
permission move the file to another location subdirectories with in this directory

x Execute Allows you to execute the file Allows you to move to the specified
Permission with read permission directory using the cd command

We can use 2 modes with the chmod command


Symbolic mode- The Permission and the user type are specified as symbols
Absolute Mode-The Permission is specified as numbers.

1. Absolute Mode- In this mode we are using a series of digits to represent the file access
permissions. The Following table explains the number that denotes each type of permissions:

Number Permission

4 Read

2 Write

13 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

Number Permission

1 Execute

To get the permission bits you want, by add up the numbers accordingly. For example, the rwx
permissions would be 4+2+1=7, rx would be 4+1=5, and rw would be 4+2=6. We are assigning separate
permissions for the owner, group, and others, so we need a three-digit number representing the
permissions of all these groups.

Example:

$ chmod 755 testfile


This would change the testfile's permissions to -rwxr-xr-x. The owner would have full read, write, and
execute permissions (7=4+2+1), the group would have read and execute permissions (5=4+1), and the
other users would have the read and execute permissions as well.

$ chmod 640 testfile


In this case, testfile's permissions would be -rw-r-----. The owner would have read and write permissions
(6=4+2), the group would have read permissions only (4), and the others wouldn't have any
Access permissions (0).

2. Symbolic Mode
In symbolic mode we are using symbols to specify the permissions and the types of the users.
The Following table represents the symbolic notation for the users.

14 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA A LINUX M-IV

The symbolic mode uses an operator to specify how the modes of a file should be adjusted. The following
operators are accepted:
+ granting a permission to a class of users

- Revoking Permission from a class of users

Example:
chmod u+x file1 Assigning Execute Permission to the Owner

chmod u-x file1 Revoking Execute Permission from the Owner

chmod u-x-w file1 Revoking Execute abd write Permission from the Owner

chmod a+x file1 Assigning Execute permission to all the users

Changing File Ownerships

To change the owner of a file uses the chown command followed by the user name of the new owner and the
target file as an argument:
 For example, the following command will change the ownership of a file named File1 to a new
owner named S4BCA
Chown S4BCA File1
 To change the ownership of multiple files or directories, specify them as a space-separated list. The
command below changes the ownership of a file named file1 and directory dir1 to a new owner
named S4BCA
Chown S4BCA File1, Dir1

15 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

Module V
Simple filter commands: pr, head, tail, cut, sort, uniq, tr - Filter using regular expression grep, egrep,sed
Understanding various Servers: DHCP, DNS, Squid, Apache, Telnet, FTP, Samba.

SIMPLE FILTER COMMANDS


1. Pr
2. Head
3. Tail
4. Uniq
5. Tr
6. Cut[Refer Module-2]
7. Sort[Refer Module-2]

1. Pr Command
The pr command prepares a text file for printing in Linux. By default, pr adds headers that include
the filename, date and time, and the page number.
[student@localhost ~]$ cat > F13

Simple filter commands: pr, head, tail, cut, sort, uniq, tr - Filter using regular expression grep, egrep, sed
Understanding various Servers :DHCP, DNS, Squid, Apache, Telnet, FTP,Samba.

[student@localhost ~]$ pr F13


2020-01-19 10:05 F13 Page 1
Simple filter commands: pr, head, tail, cut, sort, uniq, tr - Filter using regular expression grep, egrep, sed
Understanding various Servers :DHCP, DNS, Squid, Apache, Telnet, FTP,Samba.
In the above example you can see that the pr command added the current date and time, the filename and the
page number.

We can use –h option to change the header Name

1 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

[student@localhost ~]$ pr -h Syllabus F13


We can use –l option to set the length of pages in lines
[student@localhost ~]$ pr -l 15 F13
2. Head Command
Head is used to display the first parts of a file; it outputs the first 10 lines by default. You can use the -
n num flag to specify the number of lines to be displayed.
Consider the example
3. Tail Command
Tail outputs the last parts (10 lines by default) of a file. Use the -n num switch to specify the number of
lines to be displayed.
4. Uniq Command
Uniq command displays a list in which every word will occur only once. Before applying uniq command we
need to perform sorting of files.
[student@localhost ~]$ cat > F11
Blue
Green
Green
Red
Violet
Violet
Violet
[student@localhost ~]$ uniq F11
Blue
Green
Red
Violet
If the list is not sorted we can perform sort and uniq as a single command
[student@localhost ~]$ sort F11| uniq
You can count the number of occurrences of a word with 'uniq -c' command.
[student@localhost ~]$ uniq F11 -c
1 Blue

2 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

2 Green
1 Red
3 Violet
5. TR Filter
TR (short for translate) is a filter utility that deletes or translates characters from one set to another set.
Syntax is
$ tr [options] [SET1] [SET2]
[student@localhost ~]$ cat > F9
1: DBMS BCA
2: CPP MCA
3: LINUX BCA
The following command replaces each occurrence of the word BCA with MCA and display the output
[student@localhost ~]$ tr 'BCA' 'MCA' <F9
1: DMMS MCA
2: CPP MCA
3: LINUX MCA
The following command replaces each occurrence of: with - and display the output
[student@localhost ~]$ tr ':' '-' <F9
1- DBMS BCA
2- CPP MCA
3- LINUX BCA
The following command converts each occurrence of uppercase letter with lowercase and display the output
[student@localhost ~]$ tr "[A-Z]" "[a-z]" <F9
1: dbms bca
2: cpp mca
3: linux bca
FILTER USING REGULAR EXPRESSION
Regular expressions are special characters which help search data, matching complex patterns.
I. Grep
II. Egrep
III. sed

3 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

Grep
The GREP filter searches a file for a particular pattern of characters, and displays all lines that contain that
pattern. The pattern that is searched in the file is referred to as the regular expression (GREP stands for
globally search for regular expression and print out).
[student@localhost ~]$ cat gs
unix is a OS.
UniX is portable.
UNIX is free.
Linux is a freeware.
Liunix is opensourse
1. Case sensitive search: The grep command without any option will search for a particular word
from a file. The searching is case sensitive
[student@localhost ~]$ grep "unix" gs
unix is a OS.
2. Case insensitive search: The -i option enables to search for a pattern case insensitively in the give
file. It can also search substring also.
[student@localhost ~]$ grep -i "unix" gs
unix is a OS.
UniX is portable.
UNIX is free.
Liunix is opensourse
3. Displaying the count of number of matches: We can find the number of lines that matches the
given pattern
[student@localhost ~]$ grep -c "unix" gs
2
[student@localhost ~]$ grep -c -i "unix" gs
4
4. Display the file names that match the pattern: We can just display the files that contain the given
string/pattern.
[student@localhost ~]$ grep -l "unix" *
Gs

4 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

5. Checking for the whole words in a file : By default, grep matches the given string/pattern even if it
found as a substring in a file. The -w option to grep makes it match only the whole words.
[student@localhost ~]$ grep -w "unix" gs
unix is a OS.
6. Displaying only the matched pattern : By default, grep displays the entire line which has the
matched string. We can make the grep to display only the matched string by using the -o option
[student@localhost ~]$ grep -o -i "unix" gs
unix
UniX
UNIX
Unix
7. Show line number while displaying the output using grep -n : To show the line number of file
with the line matched.
[student@localhost ~]$ grep -n "unix" gs
1:unix is a OS.
5:Liunix is opensourse
8. Inverting the pattern match: You can display the lines that are not matched with the specified
search sting pattern using the -v option.
[student@localhost ~]$ grep -v -i "unix" gs
Linux is a freeware.
9. Matching the lines that start with a string: The ^ regular expression pattern specifies the start of a
line. This can be used in grep to match the lines which start with the given string or pattern.
[student@localhost ~]$ grep "^Li" gs
Linux is a freeware.
Liunix is opensourse
10. Matching the lines that end with a string : The $ regular expression pattern specifies the end of a
line. This can be used in grep to match the lines which end with the given string or pattern.
[student@localhost ~]$ grep "e$" gs
Liunix is opensourse
11. Specifies expression with -e option. Can use multiple conditions
[student@localhost ~]$ grep -e "free" -e "OS" gs

5 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

unix is a OS.
UNIX is free.
Linux is a freeware.
Egrep

Stands for Extended globally search for regular expression and print out. Which is same as grep with –e
option. Egrep is used for search multiplie patterns from a given document.
sed
Command 'sed' stands for stream editor. You can use this command to edit streams (files) using regular
expressions. But this editing is not permanent. It remains only in display, but in actual, file content remains
same.
Syntax:command | sed 's/<oldWord>/<newWord>/'
[student@localhost ~]$ cat > F10
unix is simple unix
unix is powerfull
[student@localhost ~]$ cat F10 | sed 's/unix/linux/'
linux is simple unix
linux is powerfull
[student@localhost ~]$ sed 's/unix/linux/' < F10
linux is simple unix
linux is powerfull
The above 2 commands changed the word unix to linux, But all the “unix” is not changed to “linux”. To edit
every word in a line we have to use a global replacement 'g'. It will edit all the specified word in a file or
string.
[student@localhost ~]$ sed 's/unix/linux/g' < F10
linux is simple linux
linux is powerfull
The 'd' option will let you to remove a complete line from a file. You only need to specify a word from that
line with 'd' option and that line will be deleted. But please note that all the lines having that same word will
be deleted.
[student@localhost ~]$ sed '/simple/d' < F10

6 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

unix is powerfull

LINUX SERVERS
I. DHCP Server
Computers that are connected to IP networks must be configured before they can communicate with other
host. The most essential information needed is an IP address.
A DHCP Server [Dynamic Host Configuration Protocol] is a network server that automatically provides and
assigns IP addresses.
DHCP servers assign each client with a unique dynamic IP address, without it, the network administrator
has to manually set up every client that joins the network, which can be difficult, especially in large
networks.
DHCP provides a central database of devices that are connected to the network and eliminates duplicate
resource assignments.
When a DCHP configured client connects to a network the DHCP client sends a broadcast query requesting
necessary information from a DHCP server. The DHCP server manages a pool of IP addresses and assign
the computer with an Dynamic IP address a lease time (length of time the allocation in valid).
II. DNS Server
DNS servers are responsible for translating domain names to numeric IP addresses. When users’ type
domain names such as ‘google.com’ into web browsers, DNS is responsible for finding the correct IP
address for those sites. Browsers then use those addresses to communicate with origin servers.
Our computer uses a DNS server to look up the domain name you're trying to access. The proper term for
this process is DNS name resolution, and the DNS server resolves the domain name to the IP address.
Step 1: Request information-To resolve a hostname, the first place your computer looks for the
corresponding IP address is its local DNS cache, which stores information that your computer has recently
retrieved. If your computer doesn’t already know the answer, it needs to perform a DNS query to find out.
Step 2: Ask the recursive DNS servers-If the information is not stored locally, your computer queries
(contacts) the recursive DNS servers (resolvers) from your internet service provider (ISP). Resolvers have
their own caches, and given that many of the ISP’s customers are using the same resolvers, there is a
reasonable chance that popular domains will already be cached. If this is the case for our example, dyn.com,
the process usually ends here and the information is returned to the user.

7 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

Step 3: Ask the root name servers-If the recursive servers don’t have the answer, they query the root name
servers. A root name server is a computer that answers questions about domain names, such as IP addresses.
The Root Name Servers can direct DNS queries to someone that knows where to find it.
Step 4: Ask the TLD name servers-The root name servers will look at the first part of our request, reading
from right to left — www.dyn.com — and in our case, direct our query to the top-level domain (TLD)
name servers for .com. Each TLD, such as those for .com, .org, and .us, has its own set of name servers.
These servers can refer us directly to the servers that do have the information.
Step 5: Ask the authoritative DNS servers-The TLD name servers review the next part of our request —
www.dyn.com — and direct our query to the name servers responsible for this specific domain.
These authoritative name servers are responsible for knowing all the information about a specific domain,
which is stored in DNS records. If we want to know the IP address for www.dyn.com, we ask the
authoritative name server for the address record (A record).
Step 6: Retrieve the record- The recursive server retrieves the Address Record [A record] for dyn.com
from the authoritative name servers and stores the record in its local cache for handling the further requests
from other users.
Step 7: Receive the answer- The recursive server returns the A record back to your computer. Your
computer stores the record in its cache, reads the IP address from the record, and then passes this
information to your browser. The browser then opens a connection to the web server and receives the
website.
III. SQUID
SQUID is released in July 1996.it is a proxy server and web server.
Proxy server is a server that acts as an intermediary for request from clients seeking resources from other
servers. A client connects to the proxy requesting some service such as a file, connection, web page on other
resources available from a different server. The proxy server evaluates the request according to its filtering
rules. If the request is validated by the filter the proxy server provide the resource by connecting to the
relevant server and requesting the service on behalf of the client.
Proxy servers provide varying levels of functionality, security, and privacy depending on your use case,
needs, or company policy.
If you’re using a proxy server, internet traffic flows through the proxy server on its way to the address you
requested. The request then comes back through that same proxy server (there are exceptions to this rule),
and then the proxy server forwards the data received from the website to you.

8 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

IV. Telnet
Telnet is a protocol that allows you to connect to remote computers (called hosts). Using telnet client
software on your computer, you can make a connection to a telnet server (that is, the remote host). Once
your telnet client establishes a connection to the remote host, your client becomes a virtual terminal,
allowing you to login and communicate with the remote host from your computer.
Telnet was developed in 1969. Telnet was initially developed for private use where security was not primary
concern.
Telnet Sever
Telnet server software is installed on remote host. You need to configure it before client can connect with it.
Telnet Client
Telnet client software allows you to connect telnet server. Once telnet client establishes a connection to the
remote host, client becomes a virtual terminal, allowing you to communicate with the remote host from your
computer.
V. Apache Web Server
Apache is an open-source and free web server software. When someone wants to visit a website, they enter
a domain name into the address bar of their browser. Then, the web server delivers the requested files by
acting as a virtual delivery man.
The job of a web server is to serve websites on the internet. To achieve that goal, it acts as a middleman
between the server and client machines. It pulls content from the server on each user request and delivers it
to the web.
The biggest challenge of a web server is to serve many different web users at the same time — each of
whom is requesting different pages.
We call Apache a web server; it is not a physical server, but rather software that runs on a server. Its job is
to establish a connection between a server and the browsers of website visitors (Firefox, Google Chrome,
Safari, etc.) while delivering files back and forth between them (client-server structure). Apache is a cross-
platform software, therefore it works on both Unix and Windows servers.
When a visitor wants to load a page on your website, for instance, the homepage or your “About Us” page,
their browser sends a request to your server and Apache returns a response with all the requested files (text,
images, etc.). The server and the client communicate through the HTTP protocol and Apache is responsible
for the smooth and secure communication between the two machines.

9 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)


lOMoARcPSD|16716358

S4 BCA LINUX M-V

VI. SAMBA
Many organizations need to provide network storage and print services for a range of desktop operating
systems; Linux uses the samba server to provide services that Microsoft windows clients can use.
Linux Samba Server is one of the powerful servers that help you to share files and printers with Windows-
based and other operating systems. It is an open-source implementation of the Server Message
Block/Common Internet File System (SMB/CIFS) protocols.
This means you can use a Linux server to provide file sharing, printing, and other services to other non-
native Linux clients such as Microsoft Windows.
Samba performing these 4 key things –
▪ File & print services
▪ Authentication and Authorization
▪ Name resolution
▪ Service announcement (browsing)
VII. FTP
An FTP server is a computer which has a file transfer protocol (FTP) address and is dedicated to receiving
an FTP connection. In order to ensure that connections can be established at all times from the clients, an
FTP server is usually switched on.
In order for the client to establish connection to the FTP server, the username and password are sent over
using USER and PASS commands. Once accepted by the FTP server, an acknowledgement is sent across to
the client and the session can start.
The FTP server can provide connection to users without need of login credentials; however, the FTP server
can authorize these to have only limited access.
FTP servers can provide anonymous access. This access allows users to download files from the servers
anonymously, but prohibits uploading files to FTP servers.

10 GG

Downloaded by Hentai Senpai (senpaihentai251@gmail.com)

You might also like