Administration Utilities

Chia sẻ bởi Nguyễn Việt Vương | Ngày 29/04/2019 | 98

Chia sẻ tài liệu: Administration Utilities thuộc Bài giảng khác

Nội dung tài liệu:

Administration Utilities
Objectives
Describe, use man pages and other information
Demonstrate how to communicate with users
Identify system defaults
Demonstrate how to find files
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
Related commands are listed at the end of the man page. The number in parentheses after a command is the section of the manual pages
Example
$ man passwd
PASSWD(1) User utilities PASSWD(1)

NAME

SYNOPSIS

DESCRIPTION

OPERANDS

EXAMPLE
….
SEE ALSO
finger(1), login(1), nispasswd(1), crypt(3C), passwd(5)
Table 2.1 : man page sections and their descriptions
man Pages and the man Command
To view a particular section of the man pages, include the section number with the man command and the term you are looking for:
man

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
Searching Man Pages by Keyword
If you are not sure of the command name, use the man command with -k option
man -k keyword
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
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
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
...
Which command use to create user ?
$ man -k create | grep user
newuser (8) – update and create new user in batch
smnpusm (1) – creates and mantains SMNPv3 users on a remote entity
useradd (8) – Create a new user or update default new user information
Manual Entries
Manual pages are mostly stored under /usr/man/
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
Manual Entries
Manual pages are formatted when needed, and are displayed using a pager 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
Related Commands
On most Linux systems, you can use the command whatis to print the short description of a command ("synopsis"):

$ whatis man
man (1) - format and display the on-line manual pages
man (7) - macros to format man pages

Related Commands
If you don`t know the actual name of a command, you can search 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
info Command
Not all man pages are being maintained and are therefore out of 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
Documentation in /usr/doc
Documentation that doesn’t fall under man pages and info is usually put into /usr/doc. This directory can hold a wealth of information :HOWTOs, user guides, FAQs, READMEs, …
Online Documentation
Linux Documentation Project:
http://www.tldp.org
http://www.ibiblio.org/mdw/index.html
http://www.linux.org


Identifying the System
The uname command shows system information; the command hostname also identifies the current host. uname command options are below :
System Default Files
Linux stores some command defaults in files in /etc/default directory:
Filename same as command name
Entries in the file take the form of environment variable definitions
Details of defaults defined in command manual page
Files are usually edited manually
Example :
# more /etc/default/useradd
GROUP=100
HOME=/home
SHELL=/bin/bash
SKEL=/etc/skel
Identifying Active Users
History of every login is kept in /var/log/wtmp ,can be shown by 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
Login Prompts
When you log into a Linux system via the command line, you are greeted with a message. The /etc/issue file generates this message

For users who log in remotely, the /etc/issue.net file contains a message or system identification to be printed before the login prompt
The find Command
The find command locates files using specified search criteria:
find directories search_criteria [action]
find command will search from directories and sub-directories recursively
find command will output all files that match with search_criteria
The find Command
search_criteria
-name name Finds only flies called name (can use shell wildcards: *, ?)
-user name Finds only files owned by user name
-type letter Finds files of specified type: f (plain files), d (dirs), etc.
-mtime n Finds files modified n days ago, less than (-n), greater than (+n)
-size n [cK] Finds files of size n, larger than (+n), smaller than (-n), c=chars, K=kilobytes (when omitted, 512 block size is implied)
-perm mode Find files that matchs the prmission setting of mode

The find Command
action:
-print Print filename found, it’s default
-exec cmd {} ; Executes given command ( filename will be given in place of {} )
-ok cmd {} ; Executes command but prompts for confirmation

Example 1
Search for openwin starting at the /usr directory
$ find /usr -name openwin
/usr/openwin
/usr/openwin/bin/openwin
( longlist: $ find /usr -name openwin –ls )

Search for files ending in tif starting at the /usr
$ find /usr -name ’*tif’
/usr/openwin/demo/kcms/images/tiff/ireland.tif
Example 2
Search for core files starting at the user’s home directory and delete them :
$ find ~ -name core -exec rm {} ;

Find files larger than 400 blocks (512-byte blocks ) starting at /etc
$ find /etc -size +400
Example 3
Find files, starting at /etc, file name is end with .conf and is regular file:
$ find /etc –type f –name *.conf

Find files with open permissions starting at the user’s home directory
$ find ~ -perm 777
locate Command
On most Linux systems, a database is maintained of all files in 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
Locating Commands
The which command will search from PATH environment variable 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
Interpreting Files
The file command identifies the contents of any file (file type) 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
TEXT PROCESSING
Search text in files with grep family commands: grep, egrep, fgrep

Modify text file with sed (Stream Editor)
grep Command
Use the grep command to search a file for a specified text string

If found, grep prints all lines that contain that pattern to the screen. The grep command can be used as a filter with other commands.

The grep command is case sensitive unless you use with –i option
grep Command
Command Format :
grep [option] string filename

Options :
-i Ignore case of string when searching
-v Search for all lines that do not match string
Example of grep
$ grep ‘root’ /etc/passwd
root: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
Regular Expression Metacharacters
egrep Command
The egrep command searches the contents of one or more files for a pattern using extended regular expression metacharacters.
The egrep command uses all the same options as grep.
Command format:
egrep [-options] pattern filename(s)

fgrep Command
The fgrep command searches a file for a pattern
expressed as a fixed string.
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)
Using grep
List all directories :
# ls –l | grep ‘^d’
List all users using bash shell when log in :
# grep ‘bash$’ /etc/passwd
List files and directories starting by ‘.’ :
# ls –l | grep ‘^.[^.]’
Filters
Linux traditionally has many utilities that read a stream of characters 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
sed (Stream Editor)
Use the sed program to edit data in files without opening them 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
Used by sed
sed (Stream Editor)
Delete lines with the d command:
sed ‘/pattern/d’ filename
sed ‘4d’ filename
sed ‘2,5d’ filename
Search and replace :
sed ‘s/string1/string2/g’ filename
Multiple edits: use –e option
sed –e ‘/linux/d’ –e ‘s/abc/ABC/g’ filename

Summary
Describe, use man pages and other information
Demonstrate how to communicate with users
Identify system defaults
Demonstrate how to find files
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...

Người chia sẻ: Nguyễn Việt Vương
Dung lượng: | Lượt tài: 1
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)