1. summary vim command line mode common shortcuts, and vim find, replace the method
(1), vim Common command line shortcuts
: Wq save and exit Vim
: wq forced to save and exit Vim!
: Q! The forced exit without saving, discard changes
: w filename Save as filename
G: $ to the last line
gg: 1 uncle to the first line, with
100g 100G: 100 moves to the first row 100
0 ^ cursor is moved to the position the first current line
$ cursor position to the end of the current line
(2), vim find, alternative methods
Enter "/" to enter the Find command-line mode, note that the command was looking forward "/" command as opposed to looking backwards is "?." Then enter what you're looking for and press Enter; n continue to look down, N continue to look upward.
Can make Vim ignores the case of command is set ignorcase
Replacement string
Format: s / content to find / replace content / modifiers
: [range] s / abc / ABC / [c, e, g, i]
This command is representative of the replacement string abc is ABC. The beginning of the range is used to specify a range of alternative action, such as "1,5" represents the first row to row 5, "1, $" indicates the first row to the last row, i.e. text, text can be with "%" to represent. Characters within square brackets are optional last option, meaning c are each asking for the first alternative; E does not display an error message; G replaces all matches in a row; I case insensitive.
2, the script operator summary, the use of logic operations and
arithmetic operators
-
addition
-
Subtraction
- multiplication
/ Division
% Take the remainder
Relational operators:
Comparative used in []
-eq equal
-ne not equal
-gt greater than
-lt less than
greater than or equal -ge
-le less
Comparison using [[]] in
== equal
! = Not equal
more than the
<Less than
= Greater than or equal
<= Less than or equal
* Note between brackets and expressions must be left blank
Logical Operators
== equality, equal returns true
! = Are not equal, not equal Returns true
3, scripting /root/bin/backup.sh, can be realized daily / etc / backup directory to / Roo T / mm-dd-etcYYYY in
#! / Bin / bash
echo "Start Backup"
SLEEP 2
DATE = date "+%Y-%m-%d"
cp -av / etc / root / etc $ DATE
echo "Backup Finish"
4, scripting /root/bin/nologin.sh and login.sh, and achieve a ban on charging Xu ordinary user login system
login
#!/bin/bash
[ -f "/etc/nologin" ] && rm -rf /etc/nologin && echo "User Can Login" ||echo "User Already Login"
nologin
! # / bin / the bash
[-f "/ etc / nologin"] && echo "Other the User Can Not the Login the System" || {Touch / etc / nologin; echo "Other the User Can Not the Login the System";}
. 5, scripting / root / bin / disk.sh, displays the current hard disk partition space utilization maximum value
# / bin / bash!
echo "Disk use max: df -h|grep ^/dev/[svm]d |tr -s " " "%"|cut -d% -f5|sort -rn|head -n1
"