8/9/2019 LPI 101 Ch07 Administration Utilities
1/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Chapter7
Administration Utilities
8/9/2019 LPI 101 Ch07 Administration Utilities
2/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Objectives
Describe, use man pages and other information Demonstrate how to communicate with users
Identify system defaults
Demonstrate how to find files
8/9/2019 LPI 101 Ch07 Administration Utilities
3/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
man Pages and the man Command
You can get information about most commands using man.This online help system contains the following information
about each command:
Command name
Synopsis and description
List and definition of all options
Environment and parameters
Relatedcommands are listed at the end of the man page. The
number in parentheses after a command is thesection of the
manual pages
8/9/2019 LPI 101 Ch07 Administration Utilities
4/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Table2.1 : manpagesectionsandtheirdescriptions
8/9/2019 LPI 101 Ch07 Administration Utilities
5/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
man Pages and the man Command
To view a particularsection of the man pages, include thesectionnumber with the man command and the term you are
looking for:
man
8/9/2019 LPI 101 Ch07 Administration Utilities
6/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Example
$ man passwdPASSWD(1) User utilities PASSWD(1)
NAME
SYNOPSIS
DESCRIPTION
OPERANDS
EXAMPLE.SEE ALSO
finger(1), login(1), nispasswd(1), crypt(3C), passwd(4)
8/9/2019 LPI 101 Ch07 Administration Utilities
7/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Scrolling in Man Pages
Spacebar Move forward one screen
Return Move forward one line
b Move back one screen
f Move forward one screen
q Quit the man command
/string Find forward
n Find the next occurrence of string
h Help more
8/9/2019 LPI 101 Ch07 Administration Utilities
8/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Searching Man Pages by Keyword
If you are not sure of the command name, use the man
command with -k option
man -kkeyword
Example :$ man -k insert
insque (3)insert/remove an item from queue
remque [insque] (3) - insert/remove an item from queue
wrjpgcom (1)insert text coments into JPG file
8/9/2019 LPI 101 Ch07 Administration Utilities
9/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Which command use to remove user ?
$ man -k delete
groupdel (8) - Delete a group
rmdir (2) - delete a directory
userdel (8)Delete a user
account and related files
8/9/2019 LPI 101 Ch07 Administration Utilities
10/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Which command use to modify user ?
$ man -k modify
ar (1)- creat, modify and
extract from archive
...
setpnp (8)- modify Plug and Play
BIOS device resources
usermod (8)- Modify user account
...
8/9/2019 LPI 101 Ch07 Administration Utilities
11/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Which command use to create user ?
$ man -k create | grep usernewuser (8)update and create new
user in batch
smnpusm (1)creates and mantains SMNPv3 users on a
remote entityuseradd (8)Create a new user or update default new
user information
8/9/2019 LPI 101 Ch07 Administration Utilities
12/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Manual Entries
Manual pages are mostly stored under /usr/man/ troff/nroffformat manual pages (compressed)
Formatted manual pages (compressed) are usually
temporarily stored under /var/catman/
man can be searched in multiple directories by setting the
MANPATH variable.
MANPATH=/usr/man:/usr/X11R6/man:/usr/share/man
If the MANPATH is not set then man will assume /usr/man
8/9/2019 LPI 101 Ch07 Administration Utilities
13/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Manual Entries
Manual pages are formatted when needed, and aredisplayed using apager program:
more is generally used by default
Set the PAGER variable to override the default
less is probably now much more suitable, as you can page
backwards, search for strings and patterns, and more
$ export PAGER=less
8/9/2019 LPI 101 Ch07 Administration Utilities
14/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Related Commands
On most Linux systems (that maintain the "index" or old-fashioned so-called whatis database) you can use the
command whatis to print theshort description of a
command ("synopsis"):
$ whatis man
man (1) - format and display ths on-line manual pages
man (7) - macros to format man pages
8/9/2019 LPI 101 Ch07 Administration Utilities
15/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Related Commands
If you don't know the actual name of a command, you cansearch for keywords in the synopsis with the commands
man k or its alias apropos
$ apropos manuals
man (1) an interface to the on-line
reference manuals
mdoc.samples (7) tutorial sampler for writing
manuals with -mdoc
You may run makewhatis to rebuild whatis database before
using these commands
8/9/2019 LPI 101 Ch07 Administration Utilities
16/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
infoCommand
Not all man pages are being maintained and are therefore outof date, so info yields more current information.
Some topics treated in info are not discussed in man at all,
info also uses hypertext links, so it is a more powerful utility
8/9/2019 LPI 101 Ch07 Administration Utilities
17/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Documentation in /usr/doc
Documentation that doesnt fall under man pages and infois usually put into /usr/doc or /usr/share/doc. This directory
can hold a wealth of information :HOWTOs, user guides,
FAQs, READMEs,
8/9/2019 LPI 101 Ch07 Administration Utilities
18/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Online Documentation
Linux Documentation Project:
http://www.tldp.org
http://www.ibiblio.org/mdw/index.html
http://www.linux.org
http://www.tldp.org/http://www.ibiblio.org/mdw/index.htmlhttp://www.linux.org/http://www.linux.org/http://www.ibiblio.org/mdw/index.htmlhttp://www.tldp.org/8/9/2019 LPI 101 Ch07 Administration Utilities
19/46SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Identifyingthe System
The uname command shows system information; thecommand hostname also identifies the current host. uname
command options are below :
-a All information -v OS version number
-n System name (nodename
on network )
-m Machine hardware
-s OS name -p Processor type
-r OS release number
8/9/2019 LPI 101 Ch07 Administration Utilities
20/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
System Default Files
Linux stores some command defaults in files in /etc/default directory: Filename same ascommand name
Entries in the filetake the form of environment variable definitions
Details of defaults definedin command manual page
Files are usually edited manually
Example :
# more /etc/default/useradd
GROUP=100
HOME=/home
SHELL=/bin/bash
SKEL=/etc/skel
8/9/2019 LPI 101 Ch07 Administration Utilities
21/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Identifying Active Users
History of every login is kept in /var/log/wtmp ,can be shownby the last command
The who command shows who is currently logged on to the
same system, information kept in /var/run/utmp
The whoami and id are used to identify the current user
Most Linux system have a w command, outputs more
information than who command
8/9/2019 LPI 101 Ch07 Administration Utilities
22/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Communicating with ActiveUsers
Use write to display a message on a user's terminal Users can disable messages using mesg n command
Root can always write to a user
Write all (wall) will display to all logged-in users Useful for sending out broadcasts
Used by the system shutdown mechanism
Use talk command to set up a two-way dialogue
8/9/2019 LPI 101 Ch07 Administration Utilities
23/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Login Prompts
When you log into a Linux system via the command line, youare greeted with a message. The /etc/issue file generates this
message
For users who log inremotely, the /etc/issue.net file contains a
message or system identification to be printed before the login
prompt
8/9/2019 LPI 101 Ch07 Administration Utilities
24/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
The findCommand
The find command locates files using specified search criteria:find directoriessearch_criteria [action]
find command will search fromdirectories and sub-directories
recursively
find command will output all files that match with
search_criteria
8/9/2019 LPI 101 Ch07 Administration Utilities
25/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
The findCommand
search_criteria
-namename Finds only flies called name (can use shell wildcards: *, ?)
-username Finds only files owned by user name
-type letter Finds files of specified type: f(plain files), d (dirs), etc.
-mtimen Finds files modifiedn days ago, less than (-n), greaterthan (+n)
-sizen [cK] Finds files of sizen, larger than (+n), smaller than (-n),
c=chars,K=kilobytes (when omitted, 512 block size is
implied)-permmode Find files that matchs the prmission setting ofmode
8/9/2019 LPI 101 Ch07 Administration Utilities
26/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
The findCommand
action:-print Print filename found, its default
-exec cmd {} \; Executes given command ( filename will
be given in place of {} )
-ok cmd {} \; Executes command but prompts for
confirmation
8/9/2019 LPI 101 Ch07 Administration Utilities
27/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Example 1
Search for openwin starting at the /usr directory$ find /usr -name openwin
/usr/openwin
/usr/openwin/bin/openwin
( longlist: $ find /usr -name openwinls )
Search for files ending in tifstarting at the /usr
$ find /usr -name *tif
/usr/openwin/demo/kcms/images/tiff/ireland.tif
8/9/2019 LPI 101 Ch07 Administration Utilities
28/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Example 2
Search for core files starting at the users home directory anddelete them :
$ find ~ -name core -exec rm {} \;
Find files larger than 400 blocks (512-byte blocks ) starting at/etc
$ find /etc -size +400
8/9/2019 LPI 101 Ch07 Administration Utilities
29/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Example 3
Find files, starting at /etc, which share the same inode number:
$ find /etctype fname *.conf
Find files with open permissions starting at the users homedirectory
$ find ~ -perm 777
8/9/2019 LPI 101 Ch07 Administration Utilities
30/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
locate Command
On most Linux systems, a database is maintained of all filesin the directory tree. The command locate followed by a
string, will return all files (with their full directory path)
that contain that string. The slocate command, a security
enhanced version of the locate command, is quickly
replacing locate
Create database for locate and slocate
$locate or slocate with optionsu/var/lib/slocate/slocate.db
8/9/2019 LPI 101 Ch07 Administration Utilities
31/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Locating Commands
The which command will search from PATH environmentvariable to determine the path of a executed command.
Syntax:
which
Similarly, whereis command will list program source files and
man pages beside the actual executed command. Syntax :
whereis
8/9/2019 LPI 101 Ch07 Administration Utilities
32/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Interpreting Files
The file command identifies the contents of any file (filetype) on the Linux system
# file *
feed.dat:ASCII text
myprog: iAPX 386 executable not stripped
myprog.c: C source code
runsys: commands text
Text file can be examined using standard utilities such as
less, more, or vi
Non-ASCII text files can be examined using the od or
strings command
8/9/2019 LPI 101 Ch07 Administration Utilities
33/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
TEXT PROCESSING
Search text in files with grep family commands: grep,egrep, fgrep
Modify text file with sed (Stream Editor)
8/9/2019 LPI 101 Ch07 Administration Utilities
34/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
grep Command
Use the grep command to search a file for a specified textstring
If found, grep prints all lines that contain that pattern to
the screen. The grep command can be used as a filter withother commands.
The grep command is case sensitive unless you use withi
option
8/9/2019 LPI 101 Ch07 Administration Utilities
35/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
grep Command
Command Format :grep [option]stringfilename
Options :
-i Ignore case of string when searching
-v Search for all lines that do not match string
8/9/2019 LPI 101 Ch07 Administration Utilities
36/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Example ofgrep
$ grep root /etc/passwdroot:x:0:1:Super-User:/:/sbin/sh
$ ls -la | grep -i jun 11
drwxr-xr-x 3 user1 staff 512 Jun 11 13:13 dir4
8/9/2019 LPI 101 Ch07 Administration Utilities
37/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Regular Expression Metacharacters
8/9/2019 LPI 101 Ch07 Administration Utilities
38/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
egrep Command
The egrep command searches the contents of one or morefiles for a pattern using extendedregularexpression
metacharacters.
The egrep command uses all the same options as grep.
Command format:egrep [-options] pattern filename(s)
8/9/2019 LPI 101 Ch07 Administration Utilities
39/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
8/9/2019 LPI 101 Ch07 Administration Utilities
40/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
fgrep Command
The fgrep command searches a file for a pattern
expressed as afixedstring.
It differs from grep and egrep because it regards all
characters literally, and it does NOT interpret regular
expression metacharacters specified on the command line.
Use fgrep to search for a specific pattern in a file that includes
metacharacter symbols.
Command format:
fgrep option(s) pattern filename(s)
8/9/2019 LPI 101 Ch07 Administration Utilities
41/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Using grep
List all directories :# lsl | grep ^d
List al users using bash shell when log in :
# grep bash$ /etc/passwd
List files and directories starting by . :
# lsl | grep \.[^.]
8/9/2019 LPI 101 Ch07 Administration Utilities
42/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Filters
Linux traditionally has many utilities that read a stream ofcharacters from stdin, process it in some way.and output their
result to stdout. These utilities are called filters
cat concatenate files and print on the standard output
cut remove sections from each line of files
sort sort lines of text files
head output the first part of files
tail output the last part of files
wc print the number of bytes, words, and lines in files
nl number lines of files
8/9/2019 LPI 101 Ch07 Administration Utilities
43/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
sed (Stream Editor)
Use the sed program to edit data in files without openingthem in an interactive editor, such as vi.
It allows you to specify edits, or modifications, to a file
from the command line and send the output to the
screen by default.
It is best used to make the same changes across
multiple files quickly. It is also used to read scripts that
administrators need.
Command format:sed [options] [address] command file...[>newfile]
Regular Expression Metacharacters
8/9/2019 LPI 101 Ch07 Administration Utilities
44/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
Regular Expression Metacharacters
Used bysed
8/9/2019 LPI 101 Ch07 Administration Utilities
45/46
SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102
sed (Stream Editor)
Delete lines with the d command:
sede /pattern/d filename
sede 4d filename
sede 2,5d filename
sede 5,$d filenamesede $d filename
Search and replace :
sede s/string1/string2/g filename
Multiple edits: usee option
sede/linux/des/abc/ABC/g filename
8/9/2019 LPI 101 Ch07 Administration Utilities
46/46
Summary
Describe, use man pages and other information
Demonstrate how to communicate with users
Identify system defaults
Demonstrate how to find files