0% found this document useful (0 votes)
10 views27 pages

Linux Admin Guide for BSC IT Students

The document provides an overview of Linux architecture, detailing its components such as hardware, kernel, shell, and utilities. It discusses various Linux distributions, highlighting Red Hat Enterprise Linux, Fedora, and Debian, along with the duties of a system administrator, including installation, user account management, and system security. Additionally, it explains the concept of the shell in Linux, listing different types of shells and focusing on the Bash shell.

Uploaded by

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

Linux Admin Guide for BSC IT Students

The document provides an overview of Linux architecture, detailing its components such as hardware, kernel, shell, and utilities. It discusses various Linux distributions, highlighting Red Hat Enterprise Linux, Fedora, and Debian, along with the duties of a system administrator, including installation, user account management, and system security. Additionally, it explains the concept of the shell in Linux, listing different types of shells and focusing on the Bash shell.

Uploaded by

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

www.acuityeducare.

com

Acuity Educare

LINUX SYSTEM
ADMINISTRATOR
SEM : V
SEM V: UNIT 1

607A, 6th floor, Ecstasy business park, city of joy, JSD


road, mulund (W) | 8591065589/022-25600622

Abhay More abhay_more


TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Q. Explain linux architecture with Core Diagram

Linux Structure
The Linux operating system can be visualized in terms of layers:
• Hardware
o Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).
• Kernel
o controls the computer resources and schedules jobs
• Shell
o Acts as a command interpreter that acts as an interface between users and the
operating system.
o The shell communicates with the internal part of the operating system called the
kernel
• Working:
o After logging in, Linux starts another program called the shell
o The shell interprets commands the user types and manages their execution
o The most popular shells are: tcsh, csh, korn, and bash
• Utilities (Commands)
o Comprehensive set of utilities that are universally required by Unix administrators &
users. Utilities are often referred to as commands

Today Linux in general and Red Hat Linux is at the heart of the IT organization in many companies. Large
parts of the Internet operate on Linux, using popular applications such as theApache web server or the
Squid proxy server. Stock exchanges use Linux in their real-time calculation systems, and large Linux
servers are running essential business applications on top of Oracle and SAP. Linux has largely replaced
UNIX, and Red Hat is a leading force in Linux.

Q .What are different Linux Distribution? Explain any three distributions.


• Linux comes in various flavours. The basic system is same, but the look and feel and other applications
can be different as per the distribution. In market more than 300 distribution are available.
• Each version of linux is produced by different organization, for different set of users.

Page 1 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

1. Redhat Enterprise Linux (Why Red Hat Linux and Fedora has been so successful? )
Red Hat produces the most popular distribution of Linux currently in use. It is a robust, reliable
operating system that can run on a variety of hardware, from personal computers to large
mainframes.
• One reason why Red Hat has been so successful since the beginning is the level of support thecompany
provides. Red Hat offers three types of support, and this gives companies theconfidence they need to
run vital business applications on Linux.
• The three types of Linux support provided by Red Hat are as follows

i. Hardware Support Red Hat has agreements with every major server hardware vendor to make
sure that whatever server a customer buys, the hardware vendor will assist them in fixing hardware
issues, when Red Hat is installed on it.
ii. Software Support Red Hat has agreements with every major enterprise software vendor tomake
sure that their software runs properly on top of the Red Hat Linux operating system and that the
enterprise software is also guaranteed to run on Red Hat Linux by the vendorof the operating
system.
iii. Hands-on Support This means that if a customer is experiencing problems accomplishing tasks
with Red Hat software, the Red Hat Global Support organization is there to help them by fixing bugs
and providing technical assistance.

2. Fedora Linux
• Fedora is a freely available Linux distribution that is completely comprised of open source software,
and Red Hat is providing the funds and people to manage this project. Both Red Hat and Fedora are free
of charge; with Red Hat you pay only for updates and support.
• Fedora is used as a development platform for the latest and greatest version of Linux, which is provided
free of charge for users who are interested. As such, Fedora can be used as a test platform for features
that will be included in Red Hat Enterprise Linux.
• Fedora makes an excellent choice to install on your personal computer, because it offers all thefunctions
of a modern operating system and some functions specially for home users.

3. Debian Linux
• It is used as a base for many other distributions. It provides security. Debian focuses mainly onthree
branches stable (latest release), unstable (branch that is in continuous evolution), and testing (next
release to be).

4. Ubuntu Linux
• Ubunto refers to distribution based on unstable branch of Debian distribution. It has best
looking desktop.

Another Linux Distributions are as follows:


Suse Enterprise
LinuxLinux Mint
Puppy linux
KUbuntu
Tiny core

Page 2 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Q. Explain the duties of System Administrator

System Administrator
 The “root” user account is the super user account in linux operating system.
 root user has access to everything i.e all user accounts, their home directories, and the files; all
system configurations; and all files on the system.
 A system administrator has access to “root” (Super user) account.

Duties of the System Administrator


1. Installing and configuring servers
2. Installing and configuring application software
3. Creating and maintaining user accounts
4. Backing up and restoring files
5. Monitoring and tuning performance
6. Configuring a secure system

1. Installing and configuring servers


• Server is a computer that offers some type of service to clients.
• The server may provide file or printer sharing, file transfer or web access etc.
• Servers must be configured to provide these services.
• In linux when we install and configure service, our system becomes server for that service.For
example: if we install and configure print service our system will become print server.
• System administrator installs and configures all the required servers.
• All the server is available with Linux but because of security reasons it is recommended that
Administrator must enable only those services which are required and keep other services disables.

2. Installing and configuring application software


• It is possible for individual users to install some applications in their home directories; but these
applications are not available to other users.
• If an application is to be used by more than one user, it needs to be installed higher up in the Linux file
hierarchy, which can be done by the system administrator only.
• The administrator can even decide which users may use which applications by creating a “group” for
that application and enrolling individual users into that group.
• Administrator configures user desktop and even decides what applications should appear on user
desktop menus. For example, Your Company may not want the games that ship with modern Linux
desktops to be available to users and may want to add menu items for newly installed or custom
applications. These all things are done by system Administrator.

3. Creating and maintaining user accounts


• To login to a Linux machine an account is must, this account is created by system administrator.
• Administrator or the company takes certain decisions like password for accounts given by administrator
or user himself. What contents a particular user can view. If World Wide Web access is desirable but
you wish to limit the access. The system administrator manager user accounts to fulfill all the needs.

4. Backing up and restoring files


Backing up:

Page 3 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

• There is a need to back up important files so that in the event of a failure of hardware, security, or
administration, the system can be up and running again with minimal disruption.
• Only system administrator can take system backup.
• If we have a high-capacity tape drive and several good sets of restore diskettes, we can makea full
system backup every few days.
• Once administrator decides what to back up, he need to decide how frequently backups are necessary
and whether there is a need to maintain a series of incremental backups (addingonly the files that
have changed since the last backup) or multiple full backups
Restoring Files:
• When Restoring files is also very important.
• Administrator needs to formulate a strategy for making sure system is not vulnerable tocatastrophic
disruption.
• There must be a plan for bringing the system back up in the event of a failure
• In case of system failure, backup files must be successfully restored.
5. Monitoring and tuning performance
• System tuning is an ongoing process aided by a variety of diagnostic and monitoring tools.
• Careful system monitoring and diagnostic practices give administrator an early heads-up when a
system component is showing early signs of failure, so that any potential downtime can be minimized.
Combined with the resources for determining which components are best supportedby Red Hat Linux,
performance monitoring can result in replacement components which allowto get best performance.

• Careful system monitoring plus wise use of the built-in configurability of Linux allows administrator to
squeeze the best possible performance from the existing equipment, from customizing video drivers to
applying special kernel patches to simply turning off unneeded services to free memory and processor
cycles.
6. Configuring a secure system
• There are major attacks done on machines connected to Internet, the majority of these attacks have not
targeted Linux systems, but Linux systems are not entirely immune, either to direct attack or to the
effects of attacks on machines running other operating systems.

• For example: Distributed Denial of Service (DDoS) attacks, attacks of the summer of 2001, Linux
machines themselves were invulnerable, but the huge amount of traffic generated by this “worm”
infection prevented many Linux machines from getting much Web-based work done for several weeks.
• The system administrator’s task is to make sure that no data on the machine or network are likely to
become corrupted, whether by hardware or power failure, by misconfiguration or user error or by
malicious or unintentional intrusion from elsewhere.
• Depending on how and to what a Linux machine is connected, the sensitivity of the data it contains and
the uses to which it is put, security can be as simple as turning off unneeded services, monitoring the
Red Hat Linux security mailing list to make sure that all security advisories are followed, and otherwise
engaging in good computing practices to make sure the system runs robustly.

• It is almost full-time job involving levels of security permissions within the system and systems to which
it is connected, elaborate firewalling to protect not just Linux machines but machines that, through
their use of non-Linux software, are far more vulnerable, and physical security.
Page 4 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

• For any machine that is connected to any other machine, security means hardening against attack and
making certain that no one is using your machine as a platform for launching attacksagainst others. If
you are running Web, ftp, or mail servers, it means giving access to those whoare entitled to it while
locking out everyone else.

• It means making sure that passwords are not easily guessed and not made available to unauthorized
persons like former employees should not have access to the system, and no unauthorized person should
copy files from your machine or machines. As a system administrator keep right balance between
maximum utility and maximum safety.
Q. What is shell? List Different shells in Linux.
SHELL:
• Shell is an interface between operating system kernel and end user. It is the commandinterpreter that
executes other programs.
• It provides a computer user an interface so that the user can run different commands or utilities/tools
with some input data. When it finishes executing a program, it sends an output to the user on the screen.
• $ is called the command prompt or shell prompt.
Several shells are available on RHEL

Bash
• Bash stands for Bourne Again Shell and it is the default shell on many Linux distributions.
• The Bash shell is a combination of features from the Bourne Shell and the C Shell.
• It has a command-line editor that allows the use of the cursor keys in a more "user friendly"
manner than the Korn shell.

Sh
• Bourne shell is referred to as "the shell".
• It is used in single user mode for trouble shooting purpose in Linux Operating systems.
• This is default shell for UNIX operating system.
• There is no option to re-edit previous commands.
• Bourne shell is located under /bin/sh.
• Command to open this shell is $sh

Korn Shell
• This is based on the Bourne shell.
• One enhancement is its command-line editing facility. It is possible using vi to recall and edit
previous commands.
• History mechanism was introduced in this shell.
• korn shell is located under /bin/ksh, if it is installed.
• Command to open this shell is $ksh
• Command to check executed commands $history
C Shell
• The c shell syntax is taken from the C programming language.
• It is a useful tool for anyone familiar with C programming.
• This shell is located under /bin/csh, if it is installed.
• Command to open this shell is $csh
Page 5 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

tcsh
• tcsh is like C Shell but it has number of enhancements.
• It is very popular with C programmers for R&D purpose.
• This shell is located under /bin/tcsh, if it is installed.
• Command to open this shell is $tcsh

zsh
• A shell that is compatible with Bash but offers even more features.
• This shell is located under /bin/zsh, if it is installed.

• Command to open this shell is $zsh


sash
• This stands for stand-alone shell.
• This is a minimal-feature shell that runs in almost all environments. Therefore, it is very well
suited for system troubleshooting.
• This shell is located under /bin/sash, if it is installed.
• Command to open this shell is $sash

nologin
• This shell can be used if you don’t wantto allow the user any interaction with your system
locally.
• It displays a message that an account is not available. It is intended as a replacement shell for
accounts that have been disabled or have other user level access such as ftp, pop3, smtp etc.

This shell is located under /sbin/nologin

Explain Bash Shell in Detail


BASH SHELL:
• Bash stands for Bourne Again Shell and it is the default shell on many Linux distributions.
• The Bash shell is a combination of features from the Bourne Shell and the C Shell.
• It has a command-line editor that allows the use of the cursor keys in a more "user friendly"
manner than the Korn shell.
• It also has a useful help facility allowing you to get a list of commands by typing the first few
letters followed by the "TAB" key known as automatic completion.
• Most used bash feature is history mechanism.
• The default prompt is $
• This shell is located under /bin/bash.
• Command to open this shell is $bash

Useful Bash Key Sequences:


• Ctrl+C Use this key sequence to quit a command that is not responding or taking too long to complete.
• Ctrl+D This key sequence is used to send the end-of-file (EOF) signal to a command. Use this when the
command is waiting for more input. It will indicate this by displaying the secondary prompt >.
• Ctrl+R This is the reverse search feature. It opens the reverse-i-search prompt. This feature helps you
locate commands you have used previously.
• Ctrl+Z Some people use Ctrl+Z to stop a command. It does stop the command, but it does not terminate
it. A command that is interrupted with Ctrl+Z is just halted until it is started again with the fg command

Page 6 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

as a foreground job or with the bg command as a background job.


• Ctrl+A the Ctrl+A keystroke brings the cursor to the beginning of the current command line.
• Ctrl+Bthe Ctrl+B keystroke moves the cursor to the end of the current command line.
Bash History:
• A useful aspect of the Bash shell is the history feature.
• The history mechanism helps to remember the last commands you used. By default, the last
1,000 commands of any user are remembered.
• History allows you to use the up and down arrow keys to navigate through the list of commands that
you used previously. We can see an overview of these commands when using the history command
from the Bash command line.

As an administrator, sometimes we need to manage the commands that are in the history list.There are
two ways of doing this.

1. Manage the file .bash history which stores all of the commands. Every user has such a
file,which is stored in the home directory of the user. If, for example, you want to
delete this file for the user neha, just remove it with the following command

# rm /home/Ramu/.bash history
only root user can do this. Since the name of the file begins with a dot, it is a hidden
file,and normal users cannot see hidden files.

2. A second way of administering history files, which can be done by regular users, is by
usingthe history command with -c option. This will clear the history list for the user who
uses thiscommand.

Q . List and explain commands to perform Basic File System Management Tasks.
• Everything on your RHEL server is stored in a text or ASCII file. Therefore, working with files isa very
important task when administering Linux.

List and Explain commands to work with Directories.

A. Working with Directories


1. cd
• Use this command to change the current working directory.
• When using cd, make sure to use proper syntax.
• First, names of commands and directories are case-sensitive; therefore, /bin is not the same as
/BIN.
• Next, we should be aware that Linux uses a forward slash instead of a backslash. So, use cd
/bin and not cd \bin to change the current directory to /bin.
• With cd we can provide absolute or relative paths.
• Examples:
• cd — Returns you to your login directory
• cd - — Returns you to your previous working directory
• cd ~ — Also returns you to your login directory
• cd / — Takes you to the entire system's root directory.
• cd /root — Takes you to the home directory of the root user. You must be the root user toaccess
this directory.
Page 7 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

• cd /home — Takes you to the home directory, where user login directories are usuallystored
• cd .. — Takes you to the directory one level up.
• cd ~otheruser — Takes you to otheruser's home directory, if otheruser has granted you
permission.
2. pwd
• The pwd command stands for Print Working Directory. We can often see our current directoryfrom
the command line, but if we cannot see then use this command.

3. mkdir
• If we need to create a new directory, use mkdir. With Linux mkdir, it is possible to create a complete
directory structure in one command using the -p option, something that you cannot do on other
operating systems.

For example, the command #mkdir/some/directory will fail if /some does not exist beforehand.In that
case, we can force mkdir to create /some as well if it doesn’t already exist. Do this by using the #mkdir
-p /some/directory command

4. rmdir

The rmdir command is used to remove directories. This work only on directories that are
already empty. If the directory still has files and/or subdirectories in it, use #rm -rf instead (r-
recursive, f- forcefully).

List and Explain commands to work with Files.


B. Working with Files

1. Using ls to List Files


 To manage files on your server, you must first know what files are available. For this purpose,the ls
command is used.
 Options with ls
• -a (all) — Lists all files in the directory, including hidden files (. filename). The .. and . at the top of
your list refer to the parent directory and the current directory, respectively.
• -l (long) — Lists details about contents, including permissions (modes), owner, group, size, creation
date, whether the file is a link to somewhere else on the system and where its link points.
• -F (file type) — Adds a symbol to the end of each listing. These symbols include /, toindicate
a directory; @, to indicate a symbolic link to another file; and *, to indicate an executable file.
• -r (reverse) — Lists the contents of the directory in reverse sort order.
• -R (recursive) — Lists the contents of all directories below the current directory recursively.
• -S (size) — Sorts files by their sizes.
• Wildcards (*)show a list of all files in the current directory. ls /etc/*a.* will show a list of all files
in the directory /etc that have an a followed by a . (dot) somewhere in the filename, andls [abc]*
will show a list of all files where the name starts with either a, b, or c in the current directory.

Page 8 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

cp original_file /dir1/dir2/new_file
2. Removing Files with rm
 Cleaning up the file system is a task that also needs to be performed on a regular basis.
 The rm command is used for this purpose. For example, use #rm /tmp/somefile to remove
somefile from the /tmp directory.

There are many options to rm. To view them all, enter man rm at the shell prompt.
• -i (interactive) — This is default option. Prompts you to confirm the deletion. This option canstop
you from deleting a file by mistake.
• -f (force) — Overrides interactive mode and removes the file(s) without prompting. This
might not be a good idea, unless you know exactly what you are doing.
• -v (verbose) — Shows the progress of the files as they are being removed.
• -r (recursive) — Deletes a directory and all files and subdirectories it contains. When this option is
combined with the -f option, the command becomes very powerful. For example, use # rm -rf
/somedir/* to clear out the entire contents of /somedir. This command doesn’t remove the directory
itself, however. If you want to remove the directory in addition to the contents of the directory, use
rm -rf /somedir.
o example, that you type
rm –rf / somedir (with a space between / and somedir)
o instead of
rm -rf /somedir.
o As a result, the rm command will first remove everything in /, and when it is finished
with that, it will remove somedir as well. Note that the second part of the command

is actually no longer required once the first part of the command has completed.
3. Copying Files with cp
• If you need to copy files from one location on the file system to another location, use the
cpcommand.
• To copy a file within the current directory, specify the new name as the third word on
thecommand line.

cp original_file new_file

• This command creates a new file, named new_file, with the same content as the original file.
• To copy a file to a different direcoty, specify a path as the third word on the command line:

cp original_file /dir1/dir2/

• This command creates a copy of original_file in dir2/. If the last part of the path is a filename
instead of a directory, the copy has that new name.
• This creates a new file named new_file with the contents of original_file in dir2/.

Page 9 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

mv filename /dir1/otherfile

cp /dir1/dir2/filename .
• Alternatively, if you know where the file is and would like to place a copy of it in your
currentdirectory, enter the path as word two and "." as the third word.

• The above command places a copy of filename in your current working directory.
• To copy all files from your home directory to the directory /tmp use cp ~/* /tmp
• If subdirectories and their contents need to be included in the copy command, use the option -r.
• cp normally does not copy hidden files where the name starts with a dot. If you need to
copyhidden fi les as well, make sure to use a pattern that starts with a .(dot). For example,
use cp
~/.* /tmp to copy all files where the name starts with a dot from your home directory to
thedirectory /tmp.
4. Moving Files with mv
• Common useful options for mv include:
o -i (interactive) — Prompts you if the file you have selected overwrites an existing file in
thedestination directory.
o -f (force) — Overrides the interactive mode and moves without prompting. Be very
carefulabout using this option.
o -v (verbose) — Shows the progress of the files as they are being moved.
• To move a file from the current directory to another location, enter a path as the third
word onthe command line.

• This command would remove filename from the current working directory and place it
in /dir1/otherfile directory. If no directory with otherfile name exists in /dir1, the command
willsave the contents of the original file filename under its new name, otherfile, in the
directory
/dir1.

 A path to the location of the file may be entered as the second word and "." as the thrid word.This
moves the file from the location specified in word two into our current working directory.

mv ../../filename /tmp/new_name

• The command above moves the file filename from a directory two levels up tothe
/tmp/ directory while renaming the file new_name.
• To rename the directory /somedir to /somethingelse, use command
# mv /somedir /somethingelse

5. Viewing the Contents of Text Files (Q. Explain any five commands to view the contents of text
files)
• head Command
The head command displays the beginning of a file. The format of the head command is:

head <filename>

By default, you can only read the first ten lines of a file. You can change the number of linesdisplayed by

Page 10 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

specifying a number option.

head -20 <filename>

The above command would display the first 20 lines of a file named <filename>.

• tail Command
The reverse of head is tail. Using tail, you can view the last ten lines of a file. This can be useful for
viewing the last ten lines of a log file for important system messages. You can also use tail to watchlog
files as they are updated. Using the -f option, tail automatically prints new messages from an open file to
the screen in real-time. For example, to actively watch /var/log/messages, enter the folowing at a shell
prompt (as the root user):

tail -f /var/log/messages

Press [Ctrl]-[C] when you are finished.

• more Command
The more command is a "pager" utility used to view text in the terminal window one page or screenat a
time. The [Space] bar moves forward one page.

• less Command
The format of the less command is:

less <filename>

The main difference between more and less is that less allows backward and single-line movement using
the same navigation as man pages: press the [Space] bar to go down one page, the [b] to goback one page,
the directional (or "arrow") keys to move one line at a time, and [q] to quit.
To search the output of a text file using less, press [/] and enter the keyword to search for within the file

• cat Command
The cat command can be used to view text, to create text files, and to join files. Its name is shortfor
concatenate, which means to combine files.
Entering the cat command followed by a file name displays the entire contents of the file on the
screen. Press [Ctrl]-[d] keystroke to exit.

 Display contents of file in terminal

Page 11 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

 Create a file using > sign. Every time user use this sign the file is overwritten. If you want to
append to existing file then use >>

 View contents of multiple files

 Use cat command with more and less


If file having large number of content that won’t fit in output terminal and screen scrolls upvery
fast, we can use parameters more and less with cat command as show above.
# cat /etc/passwd |
more
# cat /etc/passwd | less
 Use >> sign to append in existing file

 Display line numbers in file

• The tac Command


This command does the same thing as cat but inverts the result.
This command will dump the contents of a fi le to the screen with the last line first and the first linelast

• tac <filename>
Page 12 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Each line in the file that includes the pattern "pattern" is located and displayed

• The grep Command


The grep command is useful for finding specific character strings in a file. For example, to find every
reference made to "pattern" in the file <filename>, enter:

• grep pattern <filename>

Each line in the file that includes the pattern "pattern" is located and displayed on the screen
6. Creating Empty Files
• Touch command help us to create empty files in file system.
• For example, use
$touch somefile
to create a zero-byte file with the name somefile in the current directory.

The main purpose of the touch command is to open a file so that the last access date and timeof the file
displayed by ls is modified to the current date and time. For example, touch * will setthe time stamp to
the present time on all files in the current directory

Q . Write the short note on piping and redirection with example.

• The piping and redirection options are among the most powerful features of the Linuxcommand
line.
• Piping is used to send the result of a command to another command, and redirection sends theoutput
of a command to a file.
Piping
• The goal of piping is to execute a command and send the output of that command to the next
command so that it can do something with it.
• Exampe 1:
# ps aux

This command provides a list of all the processes that are currently running on your computer.
a = show processes for all users
u = display the process's user/owner
x = also show processes not attached to a terminal

Pipe ps with less command


# ps aux | less
We can see the complete result page by page

• Example 2:
If we want to check whether a user with the name neha exists in the user database /etc/passwdthen use
cat with grep command.
# cat /etc/password | grep neha
Redirection
• Redirection sends the result of a command to a file. This file can be a text file or a device file.
• There are various types of Redirections.
1. Redirecting Output (STDOUT) to a file
2. Using Redirect ion of STDIN
3. Separating STDERR from STDOUT
Page 13 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

4. Redirecting Output to device files


5. Cloning Devices Using Output Redirection

Q. Explain redirection? How will you redirect output to a file? Explain with example.
OR
What is STDIN and STDOUT in Redirection? Explain with example.

. Redirecting Output (STDOUT) to a File


 STDOUT is normally written to the current console.
 Redirection can be used to redirect the standard output (STDOUT) to a file.
 For Example:
• From a console window, use the command #ps aux. You’ll see the output of the commandon the
current console.
• Now use # ps aux > ~/psoutput.txt. You don’t see the actual output of the command, because
it is written to a file that is created in your home directory, which is designated bythe ~ sign.
• To show the contents of the file, use the command # less ~/psoutput.txt.

 Redirection signs:
 Use the single redirector sign (>) if you want to overwrite the content of existing files.
For Example: Existing contents of windows file will be overwritten by contents of linux file.

• Use double redirector sign (>>) if you want to append to the existing files.
Contents of linux file will be appended at the end of windows file.

2. Using Redirection of STDIN


• We can redirect output of commands to file; the opposite is also possible with redirection.
• For example, you may redirect the content of a text file to a command that will use that contentas its
input.
• For example: # mail -s “test message” root < .
• When using redirection of the STDIN, the dot is fed to the mail command immediately, and youdon’t
have to do anything else to send the message.
• If the email message is in a file then we can use it directly to send the mail.
$ mail –s “Hello world” root < ~/mailcontent.txt

Page 14 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

3. Separating STDERR from STDOUT


• For Example:
o Open a terminal session, and make sure you are not currently logged in as root.
o Now run the command using redirection of STDERR.
$ find / -name root > errors.txt
o As normal users cannot search root file system, errors will be generated and fed to
find_errors.txt

4. Redirecting Output to device files

• One of the interesting features of redirection is that, not only it is possible to redirect to regularfiles,
but you can also redirect output to device files.
• In many cases,this works only if you’re at the root.
• important device files that can be used are:
1. /dev/null The null device. Use this device to redirect to nothing.
2. /dev/zero A device that can be used to generate zeros. This can be useful when creatinglarge
empty files.
3. /dev/ttyS0 The first serial port.
4. /dev/lp0 The first legacy LPT printer port.
5. /dev/hda The master IDE device on IDE inter face 0 (hard drive).
6. /dev/hdb The slave IDE device on IDE inter face 0 (not always in use).
7. /dev/hdc The master device on IDE inter face 1 (typically your optical drive).
8. /dev/sda The first SCSI, SAS, serial ATA, or USB disk device in your computer.
9. /dev/sdb The second SCSI or serial ATA device in your computer.
10. /dev/vda The name of your hard disk if you’re working on a vir tual machine in a KVM
virtual environment.
11. /dev/sda1 The first par tition on the first SCSI or serial ATA device in your computer.
12. /dev/tty1 The name of the first text-based console that is active on your computer. Thesettys
are available from tty1 up to tty12.
• For Example:
#cat /etc/passwd > /dev/tty12
• This will move output of passwd file to tty12. To view this, use the Ctrl+F12 key sequence forCLI or
Ctrl+Alt+F12 if you are working in a graphical environment.
5. Cloning Devices Using Output Redirection
• We can redirect contents of a storage device by using redirection.
• For example: We can clone sda disk to sdb by using
# cat /dev/sda > /dev/sdb
• Redirecting to devices, can be very dangerous. Imagine if you use the command cat
/etc/passwd > /dev/sda. It will dump the content of the passwd file to the beginning of the
/dev/sda device. Since you are working on the raw device, no file system information is used,so this
command would overwrite all impor tant administrative information stored at the beginning of the
device.
• A more efficient way to clone devices is to use the dd command. The advantage of using dd isthat it
handles I/O in a much more efficient way.
• To clone a device using dd, use
# dd if=/dev/sda of=/dev/sdb
Before you press Enter, make sure there is nothing you want to keep on the /dev/sdb device.
Page 15 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Q .What is a cron file write steps to run a task from cron or job scheduling.

• cron is used to automatically run jobs at time.


• cron consists of two parts.

o First there is the cron daemon, a process that starts automatically when your server boots.
o The second part is the cron configuration. This is a set of different configuration files thattell
cron what to do.

• After creating the cron configuration fi le, the cron daemon automatically picks up the changes,and it
will make sure that the job runs at the time indicated.
• The cron daemon checks its configuration every minute to see whether there are any new tasksthat
should be executed.
• cron jobs are started from the directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and
/etc/cron.monthly.

• Example: In a crontab specification, the time indicator 0 2 3 4 * indicates that a cron job willstart
on minute 0 of hour 2 (which is 2 a.m.) on the third day of the fourth month. Day of week is
not specified, which means the job would run on any day of the week.

• In a cron job defi nition, we can use ranges as well. For instance, the line */5 * * * 1-5 meansthat a
job has to run every five minutes, but only on Monday through Friday.

• We can also supply a list of comma-separated values, like 0 14,18 * * *, to run a job at 2 p.m.and at
6 p.m.

Running a Task from cron:


1. Open a terminal, and make sure you are logged in with your normal user account.# su
– acuity

2. Open the crontab editor.


$ crontab -e

3. Type the line to send an email message every five minutes:


*/5 * * * * mail -s "hello root" root <

Page 16 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

4. Use the vi command :wq! to close the crontab editor and save your changes.

5. Wait five minutes. Then, in a root terminal, type mail to start the command-line mail program to
check mail sent by acuity.

6. Go back to the terminal where you are logged in with the normal user account, and type
$crontab -r.
This deletes the current crontab file for user account acuity.

Q . What are links write steps to create link or explain the concept of hardlink and symbolic
link.

• In a Linux file system, we can access a single file from different locations using links.
• Because of this we need not copy files to different locations and make versions.
• A link looks like a regular file, but it’s more like a pointer that exists in one location to show wehow
to get to another location.
In Linux, there are two different types of links. A symbolic link and Hard link.

Symbolic Link/ soft link Hard Link


A file can be accessed using different A file can be accessed using many different
references pointing is known as a softlink. names known as hard links.

Soft Links have different inodes Hard Links have same inodes number as of
numbers than original files. original files.
Soft Link contains the path of original These links have actual file contents.
file and not the contents.
When the original file is removed, the link Even if the original file is removed, the link
becomes a 'dangling' link that pointsto will still show you the contents of the file.
nonexistent file.
You can make soft links to files and You cannot create a Hard Link for a
directories. directory.
Symbolic links can point to any file system Hard links are only valid within the same File
as they are simply the name ofanother System.
file.
The command used for a soft link is “ln the command used for the creation of hardlink
–s” is “ln”
Memory consumption is less Memory consumption is more.
Relative path and absolute path bothare Relative path is not allowed in a hard link.
allowed in soft links
Page 17 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Example:

# vi a ---> create a file called "a"


#ln a b ---> create hard link called "b" to "a"
#ln -s a c ---> create soft link called "c" to "a"

Printing the contents of files a, b and c produce the same result:


# cat a ---> hello
# cat b ---> hello
# cat c ---> hello

Check inode of links


# ls -il a b c
Now we remove the original “a” file:
# rm a

And the difference between the two links:


# cat a ---> No such file or directory
# cat b ---> hello
# cat c ---> No such file or directory

Q. Write short notes on creating backup OR Write steps for Creating Backups OR Write
steps to Archive and extract files using tar.

• tar command is used to take backup of important files on your computer.


• It is used for creating and extracting backups on Linux.
• Three major tasks are involved in using tar: creating an archive, verifying the contents of an
archive, and extracting an archive.
• You can write the archive to multiple destinations, but the most common procedure is to write itto a
file.
• While using tar, use the f option to specify which file to work with.

Archiving and Extracting with tar:


Archive the contents of the /etc directory into a tar file.

1. Open a terminal, and use the following command to write an archive of the /etc directory to
/tmp/etc.tar:
# tar -zxvf /tmp/etc.tar /etc

2. Verify tar archive in /etc directory.


# file /tmp/etc.tar
3. Show the contents of the archive.
# tar -tvf /tmp/etc.tar

4. Extract the archive in the /tmp directory.


# tar -xvf /tmp/etc.tar

Page 18 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Q . Write steps for Mounting Devices

• When we connect the device to a directory in the root file system, the process is known as
mounting the device.
• To mount a storage device, you first need to find out two things: what is the name of the
• device and the directory to mount it.

Mounting a USB Flash Drive:

1. Open a terminal, and make sure you have root privileges.


2. Use blkid command to find name of your disk.
3. Use fdisk -cul /dev/sda to find current partitions. Assume two partitions.
4. Use mount /dev/sda2 /mnt to mount partition on /mnt directory.
5. Use cd /mnt to go into the /mnt directory.
6. Type ls to verify that you see the contents of the partition 2.
Come out of /mnt directory and dismount using umount /dev/sda2.

Q. List commands for Managing Printers.

• The easiest way to setup a printer is by using the graphical system-config-printer utility.This
utility helps in setting up a local printer that is connected directly to your computer. It also gives you
access to remote print queues.
• CUPS (Common UNIX Print System) use the Internet Printing Protocol (IPP), a generic standard for
printer management. You can also manage your CUPS environment using a web-based interface that
is available at http://localhost:631

Page 19 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Q. Explain System and Process Monitoring and Management.


OR
What do you understand by system and process monitoring and Management? Explain
using commands .
OR
Short notes on Monitoring and tuning performance.

• Tasks that run at given moment on Red Hat Enterprise Linux Server are referred to asprocesses.
• Managing processes is an important work for a system administrator.

• ps command is used to find out what a specific process is doing on server.


• Two useful ways to use the ps commands are
• # ps afx, returns a treelike overview of all current processes
• # ps aux, returns usage information for every process.

• When using ps aux, process information is shown in different columns:


USER The name of the user who run process.
PID The process identification number
%CPU The percentage of CPU cycles used by a process.
%MEM The percentage of memory used by a process.
VSZ The virtual memory size. Total memory claimed by a process.
RSS The resident memory size. Total memory process is actually using.
TTY If the process is started from a terminal then it shows device name of the terminal STAT The
current status of the process. S for sleeping, R for running, or Z for zombie state.START The time
that the process started.
TIME Time in seconds that a process has used CPU cycles since it was started
COMMAND The name of the command file that was used to start a process. If the name of this fileis
between brackets, it is a kernel process.
• In ps afx, f option shows the relationship between parent and child processes. To kill a process,we
need to know parent process.

Sending Signals to Processes with the kill Command:

Page 20 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

• To send signals to processes, you use the kill command.


• This command has two arguments.
• First argument is the number of the signal you want to send to the process
• Second argument is the PID of the process to which you want to send a signal.
• Example: # kill -9 1234 will send the SIGKILL signal to the process with PID 1234.
• Three signals are available in linux: SIGHUP (1), SIGKILL (9), and SIGTERM (15).
• Each of these signals can be referred to by the name of the signal or by the number for
managing processes.

1. SIGTERM is used to ask a process to stop its activity, the process close all open files and stopusing
its resources.
2. SIGKILL, doesn’t allow the process any time at all to stop its activity; that is, the process is
simply cut off, hence there is risk of damaging open files.
• For example: # kill -9 123 or kill -SIGKILL 123
• The above command sends the SIGKILL signal to the process with PID 123.
3. SIGHUP signal tells a process that it should reinitialize and read its configuration files again.

killall Command:
• When using the kill command, you can use the PIDs of multiple processes to send specificsignals
to multiple processes simultaneously.
• Another way is to use killall command, which takes the name of a process as its argument.
• For example: # killall -SIGTERM hpptd
• The above command sends the SIGTERM signal to all active httpd processes.

Using top to Show Current System Activity:


• The top program allows to monitor current process activity and perform some basic
management tasks.
• If you notice that a process is very busy, you can press the k key to terminate that process.
• The top program will first ask for the PID of the process to which you want to send a signal (PIDto
kill). After you enter this, it will ask which signal you want to send to that PID, and then it will
immediately operate on the requested PID.
• It also shows tasks your server is currently handling and what each of these tasks is doing. Inthis
line, you will find four status indications.
a. Running the number of active processes.
b. Sleeping the number of processes currently loaded in memory, which not doing any activity.
c. Stopped the number of processes that have been sent a stop signal but haven’t yet freed allthe
resources they were using.
Zombie the number of processes that are in a zombie state. This is an unmanageable process state
because the parent of the zombie process has disappeared and the child stillexists but cannot be
managed because the parent is needed to manage that process

Q .Explain find command with following options: -name, -user, -mtime,


OR
Which command is used to search files? Explain with example.
• We can find files using find command.
• This command can find files based on any property the file may have.
• We can use find to search for files based on any file property, such as

Page 21 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

o their names;
o the access, creation, or modification date;
o the user who created them;
o the permissions set on the file; etc.

• Example 1:If we want to find all files whose name begins with hosts, use
# find / -name "hosts*"

• Example 2:Find is useful to locate files that belong to a specific user. Command to locate allfiles
created by user maya.
# find / -user "maya"

• Example 3:Find any file less than 3 days old.


# find / -mtime -3

• Example 4: Find .txt file less than 3 days old.


# find . –name “*.txt”-mtime -3
(. (DOT) – current working directory)

• Example 5: Find file having size larger than 10000k


# find . size +10000k

Q .List common yum commands. How to install software with yum


OR
Short notes on searching installing and updating OR Explain any five common
commands yum?

Example: Installing Samba package in our system.


1. Use yum provides to search packages containing a specific file
# yum provides */samba

2. Request more information about the package.


# yum info samba

3. Installing package with yum install


# yum install samba
The command provides you with an overview of the package and its dependencies, and it askswhether
you want to install it. Answer by typing y on your keyboard.
4. To update installed packages.
# yum update samba

Page 22 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

Q . List different query options for installed packages OR What are the general RPM
command line options?

 rpm -qa | wc -l ( Shows total Package installed in your system ).


 rpm -qa | grep [Package name] ( find the installed package from your system.
 rpm -ihv [ package location ] ( locally installed rpm packages )
 rpm -e [ Package Name ] ( Removing package from your system )

Q. Write steps to Extract Files from RPM Packages.

• Software installed on your computer may become damaged. In this situation you can extractfiles
from the packages and copy them to the original location of the fi le.
Page 23 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

• Every RPM package consists of two parts: the metadata part that describes what is in the
package and a cpio archive that contains the actual files in the package.
• If a file has been damaged, you can start with the rpm -qf queryoption to find out from what
package the file originated.
• Next use rpm2cpio | cpio -idmv to extract the files from the package to a temporary location.

Example:
1. Use rm -f /usr/sbin/modem-manager.
2. Use rpm -qf /usr/sbin/modem-manager. This command shows that the file comes from the
ModemManager package.
3. Copy the ModemManager package file from the repository cp /repo/ModemM[Tab] /tmp
command.
4. Change the directory to the /tmp, and use rpm2cpio |cpio -idmv to extract the package.
The command in step 4 created a few subdirectories in /tmp. Activate the directory /tmp/usr/sbin,where
you can find the modem-manager file. We can now copy it to its original location in /usr/sbin

Q . Write a note on RPM and YUM in Linux.


OR
Distinguish between RPM and YUM (Meta Package Handler).

RPM YUM
RPM is the RedHat Package Manager. Meta Package Handler, which in Red Hat is
known as yum (Yellowdog Update Manager)
RPM cannot resolve dependencies on its own. YUM resolves dependencies with ease. It can
find dependencies and download required
files even if they're not in the system.
If we want to install an application(Ex: apache), Install an application with single command
rpm need to install all the packages required for Ex: yum install httpd
this application, these packages may vary from
1 rpm to several rpm’s depending on shared
rpm packages.
with the "rpm" command, you need to know with "yum", you just need to know the name
theexact location of the .rpm package of package, and if it's available through your
repositories list, it will be installed along with
its dependencies
RPM can’t handle updated software installation Does YUM install updates of the existing
automatically packages by using
yum install upgrade
RPM allows to install more than one version of YUM will inform us the previous version of the
any file at the same time. package that is already installed in your
system. It does not allow us to install its
multiple versions.
Page 24 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

RPM Cannot connect to online repositories YUM can connect to on-line repositories to
get latest software before installing the
applications.

These are the package manager of Redhat Distro. This command also checks the repository metadata for
files that are in a package, and it tells you exactly which package you need to find a specific file.

 Package manager tool is for installing, updating, removing, and managing software packages in Red
Hat Enterprise Linux System.
 yum uses numerous third-party repositories to install packages automatically by resolving their
dependencies issues.
 yum also install any dependencies which is related to that packages.
 For the update of the system via yum you required internet connection.
 So in CentOS, Redhat, Fedora we use yum package Installer & In Ubuntu, Debian system you use apt-
get package installer

Q . What is a repository write steps to create and manage a repository OR How to set up your
own repository?

• If you have a Red Hat server installed that doesn’t have access to the official Red Hat Network(RHN)
server repositories, you’ll need to set up your own repositories.
• This procedure is also useful if you want to copy all of your RPMs to a directory and use that
directory as a repository.

1. Create a directory that you can use as a repository in the root of your server’s file system.
# mkdir /repo

2. Insert the Red Hat installation DVD in the optical drive of your server. Assuming that you runthe
server in graphical mode, the DVD will be mounted automatically.

3. Go into the mounted DVD.


# cd /media/RHEL[Tab]
Go to the directory where all RPMs are by default. Now use
# cd Packages
Copy all packages to the /repo directory you just created.
# cp * /repo

4. Go to the /repo directory.


# cd /repo
To install createrepo, you first need to install the deltarpm and python-deltarpm packages.
# rpm -ivh deltarpm[Tab] python-deltarpm[Tab]
Install the createrepo package.
# rpm -ivh createrepo[Tab]

5. Create the metadata that allows you to use the /repo directory as a repository.

Page 25 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V: LINUX – U4

# createrepo /repo
6. Create a file with the name /etc/yum.repos.d/myrepo.repo using vi editor.
# vi /etc/yum.repos.d/myrepo.repo
[myrepo]
name=myrepo
baseurl=file:///re
pogpgcheck=0

7. Check outputs.
# yum repolist
# yum search nmap

• In myrepo.repoconfiguration file, The file:// part is the URI, which tells yum that it has to look ata
file, and after that,you need a complete path to the file or directory i.e/repo.
To check whether packages have been tampered usegpgcheck=1 else gpgcheck=0. If it is setto 1 then we
need to configure GPG check

Q. How to manage Process Niceness.


• By default, every process is started with the same priority.
• But, sometimes processes may need additional time, or give their time to other processes ifother
process is more important.
In these cases, you can change the priority of a process by using the nice command.

When using the nice command, we can adjust the process niceness from -20, which is good forthe
most favorable scheduling, to 19 for the least favorable scheduling.
By default, all processes are started with a niceness of 0.
For example: you want to adjust the niceness of the find command, then get PID using followingcommand.
# ps aux | grep find
Assuming the PID is 1234, you can use
# renice -10 1234

Using nice to Change Process Priority:


1. Open a terminal window as root.
2. Type the command dd if=/dev/zero of=/dev/null &, and repeat this four times.
3. Start top. You’ll see the four dd commands listed at the top. In the PR column, you can see thatthe
priority of all of these processes is set to 20. The NI column, which shows the actual process niceness,
indicates a value of 0 for all of the dd processes, and, in the TIME column, you can see that all of the
processes use about the same amount of processor time.
4. From Top interface press r. On the PID to renice prompt, type the PID of one of the four dd
processes, and press Enter. When asked Renice PID value: type 5, and press Enter.
5. With the previous action, you lowered the priority of one of the dd commands. You should
immediately start seeing the result in top, because one of the dd processes will receive a lower
amount of CPU time.
6. Repeat the procedure to adjust the niceness of one of the other dd processes. Now use a niceness
value of -15. You will notice that this process now tends to consume all of the available resources on
your computer. Thus, you should avoid the extremes when working withnice.
Use the k command from the top interface to stop all processes where you adjusted the niceness.
Page 26 of 26
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622

You might also like