vim text editor; Pipes and file redirection; Users and Groups

The second week of knowledge summary

  The second week mainly study the text editor vim, vim supports powerful text editing features, you need to master some of their usual function, and the standard IO pipeline ,, as well as user groups and permissions management.

A. The text editor vim

1. Text editing tool

vi: Visual editor, text editor,
text: ASCII, Unicode
text editor Category: Line Editor: sed
full-screen editor: nano, vi, vim

2. Mode Editor

Three main modes:
1. Command (Normal) Mode:
default mode, move the cursor, cut / paste text
2. Insert (the Insert) or edit mode: Review Text
3. extended command (extended command) mode: Save and exit
Esc to exit the current mode,
Esc key Esc key always returns to the command mode

3. Common Commands

1. close the file
1.1 Extended Command Mode:.
: Q Exit
:! Q Force Quit, discarding modifications made
: wq save and exit
: x save and exit
. 1.2 Command Mode
ZZ save and exit
ZQ not save and exit
2. Extended Command Mode
Press " : "Ex mode
. 2.1 Creating a command prompt: at the bottom left of the screen is
2.2 common commands.
w write (save) the disk file
wq write and quit
x written and exit
q quit
q! Exit without saving, even if the changes are lost
r filename read the contents of the file to the current file
w filename write the contents of the current file to another file
! Run command
r! Read into the output of the command command
3. Command Mode Command
3.1. Between the lines : moving
the extended command mode or #G: # # Go to the first row
G last row
, gg 1G first row
between the sentence under a mobile :) (on a
movement between paragraphs: {} for some period at the
3.2 characters. edit:
the X-cursor to delete characters
#x delete the cursor at the start of the # character
position behind the characters and their character at the cursor xp exchange
~ Change case
J delete the current line feed line
Replace command (R & lt, Replace)
R & lt replacement character at the cursor
R REPLACE mode is switched to the
3.3 delete command:.
D deletion command, the character cursor jumps can be combined to achieve Clear
remove the end of the line d $
d ^ to delete the first non-blank line
d0 to remove the first line
DW
de
DB
#COMMAND
dd: delete line cursor
#dd multi-row delete
D: have been deleted from the current cursor position to the end of the line, is equivalent to D $
4. extended command mode
4.1. delimited address
/ pattern / match pattern row
 / pat1 /, / pat2 /
from the first pattern to be matched pat1 line until the first row is matched to pat2 end
#, / PAT /
/ PAT /, $
 use: followed by an edit command
Dy
W file: the range of lines saved to the file specified in the
r file: insert all contents of the specified file in the specified location
4.2 find and replace.
/ PATTERN: Find the current cursor location to the end of the file
PATTERN:? seek from the current cursor location to the header file
n: with the command in the same direction
N: reverse direction command
is completed in the extended search and replace operation mode command
format: the content s / to find / replace content / modifier
content to find: mode may be used
alternatively as the content: mode can not be used, but after use \ 1, \ 2, ..., etc. to the reference symbol; may also
use "&" found for the previous reference the entire contents of lookup

Modifier:
I ignore case
g global substitution, by default, each row replaces only the first occurrence
gc global Alternatively, each query before replacement
 search and replace delimiter / may be replaced with other character
s @ / etc @ / G @ var
S # / Boot # / # I

II. Standard IO and pipes

1. The standard input and output

1.1 Open the file has a fd: file descriptor (file descriptor)

Linux to the program provides three I / O devices
 standard input (STDIN) -0 default accept input from a keyboard
 standard output (STDOUT) -1 default output to the terminal window
 standard error (STDERR) -2 default output to the terminal window
I / O redirection: change the default location

1.2. The output and error redirected to file

STDOUT and STDERR can be redirected to a file
command operation symbol file name
Supported operating symbols include:
\> to STDOUT redirected to a file
2 \> The STDERR redirected to a file
&> to redirect all output to a file
\> file content It will be covered with
set -C prohibited content will overwrite the existing file, but can be added
\> | file mandatory coverage
set + C allows you to override
\ >> original content on the basis of additional content

1.3. The output and error redirected to file

2> covering redirect errors output data stream
2 >> append redirection error output stream
 standard output and error are each directed to a different location
COMMAND> /path/to/file.out 2> / path / to / error. OUT
 combined error output and standard output of the same data stream to redirect
&> coverage redirection
& >> append redirection
COMMAND> /path/to/file.out 2> & 1 (the order is important)
the COMMAND >> / path 2 /to/file.out> & 1
Ø (): STDOUT combine multiple programs
(cal 2007; cal 2008)> all.txt

2.tr command

tr conversion and delete characters
tr [OPTION] ... SET1 [SET2]
 options:
-c -C --complement: Take character sets complement
-d --delete: delete all characters belonging to the first character set
- s --squeeze-repeats: continuous duplicate characters are represented by a single character
-t --truncate-set1: the first character corresponding to a character set into a second set of characters corresponds to the character
[: alnum:]: letters and digital [: alpha:]: letters [: cntrl:]: control (non-printing) characters
[: digit:]: digital [: graph:]: graphic character [: lower:]: lowercase letters [: print:]: can printing characters
[: punct:]: punctuation [: space:]: whitespace characters [: upper:]: uppercase letters
[: xdigit:]: hexadecimal characters

3. Pipeline

Pipe (using "|" symbol shown) for connecting the command
command 1 | Command 2 | Command 3 | ...
Ø command 1 is sent to STDIN STDOUT 2 command, the command sent to the command STDOUT 2 3
STDIN
STDERR not default through line forwarding, available 2> & 1 | & implement
 last command is executed in the sub-shell process of the current shell process in
 combination of functions of multiple tools
LS | TR 'a-Z' 'a-the Z'
less: a a view input
LS the -l / etc | less
mail: send by e-mail input
echo "the Test Email" | mail -s "the Test" [email protected]
bc: arithmetic
echo "2 ^ 3" | bc

III. User groups and rights management

1. The group of categories

 Category Linux group
user's primary group (primary group)
the user must belong to one and only one main group
group name with the user name, and contains only a user private group
additional group of users (supplementary group)
a user can belong to zero or a plurality of auxiliary groups

2. The user and group profiles

Linux main configuration file and user groups:
/ etc / the passwd: users and their attribute information (name, UID, primary group ID, etc.)
/ etc / Group: Group attribute information and
/ etc / shadow: attributes and their associated user password
/ etc / gshadow: group password and their associated properties

3. The user and group management commands

3.1 users to create: useradd

useradd [Options] LOGIN
-u UID
-o -u option with no check UID uniqueness
-g GID specified in the basic group the user belongs, for the group name, or GID
-c "the COMMENT" user comment information
-d HOME_DIR specified path (not present) to the home directory
specified in the user's default shell -s sHELL, the list of available / etc / shells file
-G GROUP1 [, GROUP2, ...] for the user to specify additional groups, groups subject to prior presence
-N not create a private group group shots, the shots using the group users group
-r create a system user. 6 the CentOS: ID <500, the CentOS. 7: ID <1000
-m create home directory for users of the system
-M home directory is not created , a non-system user

3.2. Modify User Properties

the usermod [OPTION] the Login
-u UID: new UID
-g GID: new main group -G GROUP1 [, GROUP2, ... [ , GROUPN]]]: Additional new group, the original group will be additional
coverage; if you keep original, will have to use the -a option
-s SHELL: new default SHELL
-c 'the cOMMENT': a new annotation information
-d hOME: home directory is not automatically created; To create a new home directory and mobile home original data,
Meanwhile -m option
-l login_name: new name
-L: lock the specified user, increase in the / etc / shadow password bar!
-U:! UNLOCK specified user, the / etc / shadow the password field is removed
-e YYYY -MM-DD: indicates that the user account expiration date
-f iNACTIVE: set period of inactivity

3.3. Modify user password

3.3.1. Password

passwd [OPTIONS] UserName: Specifies the user to modify the password
 Common options:
-d: delete the specified user password
-l: Lock the specified user
-u: To unlock a specific user
-e: Login to force the user to change the password the next
-f: Force Operation
- n mindays: specifying a minimum period of use
-x maxdays: the maximum period of use
-w warndays: how many days in advance began to warn
-i inactivedays: inactive period
--stdin: receiving a user password from standard input

3.3.2. Change Password

chage [OPTION]... LOGIN
-d LAST_DAY
-E --expiredate EXPIRE_DATE
-I --inactive INACTIVE
-m --mindays MIN_DAYS
-M --maxdays MAX_DAYS
-W --warndays WARN_DAYS
-l 显示密码策略

3.4. Group Management Command

3.4.1.groupadd [OPTION]... group_name

-g GID GID number specified; [GID_MIN, GID_MAX]
-R & lt creates a system group

3.4.2. Modify and delete groups

Modify Group Properties: groupmod
groupmod [OPTION] ... Group
-n group_name: new name
-g GID: new GID
 group deletion: groupdel
groupdel the GROUP

3.4.2 Changing the password set

Group Password: gpasswd
gpasswd [OPTION] the GROUP
-a user to add a user to a specific group
-d user to remove the user from the specified user group
-A user1, user2, ... provided with administrative privileges user list
newgrp command : temporarily switch primary group
if a user does not belong to this group, the group password is required

3.4.2 Changing the password set

groupmems [Options] [Action]
Options: -g, --group GROUPNAME change to the specified group (only root)
Actions:
-a, --add username specified user to join the group
-d, --delete username delete users from a group
- p, --purge removed from all members of the group
-l, --list display a list of group members
groups [OPTION]. [USERNAME] ... view the list of groups the user belongs

3.5. File Permissions

3.5.1. Modify the owner and group file

Modify the file owner: chown
chown [OPTION] ... [OWNER] [: [the GROUP]] ... the FILE
instructions:
OWNER
OWNER: the GROUP
: the GROUP, colon can also be replaced.
-R & lt: recursively
chown [OPTION] ... --reference = RFILE fILE ...
is a group of the modified file : chgrp
chgrp [the OPTION] ... ... the fILE the gROUP
chgrp [the OPTION] ... --reference = RFILE fILE ...
-R & lt recursion

3.5.2. File Permissions

File:
r file can be used to view class tools to get its content
w can modify its content
x can put this document to draw the kernel starts a process
directory:
r You can use ls to view this directory in the file list
w can create files in this directory, too You can delete files in this directory
x can use ls -l to view this directory in the file metadata (must be compatible with r), can cd into the directory
X x permission only to the catalog, do not give permission to file x
file permissions operation command: chmod
file permissions (rwx | X)
vim text editor; Pipes and file redirection; Users and Groups

Modify file permissions
the chmod [the OPTION] ... ... the FILE OCTAL the MODE-
-R & lt: recursively modify permissions
chmod [the OPTION] ... the MODE [, the MODE] ... ... the FILE
the MODE:
Review of a class of users All permissions
u = g = o = ug = a = u =, g =
modified by a user or a certain class of permission bits
u + ug + g- o + o- a + a- + - chmod [OPTION] ... --reference = RFILE fILE ...
reference RFILE file permissions will be modified to the same RFILE fILE

3.6. Special file permissions

3.6.1. SUID permissions on executable files

  Any executable file can not start for the process: the initiator of the program depends on whether the file has
execute permission
after  start for the process, which is the main process for the original owner of the program file
SUID valid only for binary executable program
 SUID is set on a directory meaningless
 permissions:
chmod + U S FILE ...
chmod US FILE ...

3.6.2.SGID rights

3.6.2.1. SGID permissions on executable files

  Any executable file can not start for the process: the initiator of the program depends on whether the file has
execute permission
after  start for the process, is a group which is a group process for the original program files
setting  permissions:
chmod + G S FILE ...
chmod GS FILE ...

3.6.2.2. SGID permissions on the directory

  By default, when a user creates a file, it is a primary group the user belongs to the group  Once a directory is set SGID, then this directory for this purpose have write access to user-created files in this directory
group belongs to this end It is a group directory
 often used to create a collaborative directory
 permissions:
chmod + G S DIR ...
chmod GS DIR ...

3.6.3.Sticky 位

  Directory is usually the user has write permissions can delete any files in that directory, regardless of the file permissions
or ownership
 Sticky bit is set in the directory, only the owner or the root file can delete the file
sticky provided on the document meaningless
 permissions:
chmod + t O DIR ...
chmod OT DIR ...

3.7 Access Control Lists

3.7.1.ACL: Access Control List, flexible rights management

In addition to the owner, owning group, and others documents, more users can set permissions
ACL take effect sequence: owner, custom user, custom groups, others
files and directories for multiple users or groups grant access rwx
-o acl Mount / Directory
the getfacl File | Directory
the setfacl -mu: wang: rwx File | Directory
the setfacl -mg: Admins: rw File | Directory
the setfacl -xu: wang File | Directory
the setfacl -b file1 clear all ACL permissions
getfacl file1 | setfacl --set-file = - file2 copy file1 file2 permissions to the acl

3.7.2.mask

mask affects only the largest human rights group in addition to the owner and the other of
the mask needs to be a logical AND operation with the user's permission to become a limited privilege (as Effective
Permission)
Set user or group permissions must exist in the mask set to take effect within the scope of
the setfacl -m mask :: rx File
--set option will delete all existing ACL entries, with a new alternative, it is noted that we must include
UGO settings, not the same as -m I can just add ACL

Guess you like

Origin blog.51cto.com/14451166/2426433