vi, etc directory files, environment variables, aliases, functions

 

1 vi command tips supplement

1.1 How to quickly edit text

yy --- quickly copy the contents of the file
3yy --- copy three lines
p --- quickly paste text
3p --- Paste three lines
dd --- quickly delete the file contents (essence is the shear)
3dd --- delete three lines
dG --- delete the cursor to the end of all content
r --- quick substitution character information
--- R & lt plurality of character information can be continuously replaced
u --- before the withdrawal operation undo = u
ctrl + r --- r = redu cancel undo

Errors often occur when using 2. vi

2.1 operating errors

vi / oldboy / can not be directly edited directory
The directory where the file must exist editor vi /oldgirl/oldboy.txt

2.2 can not save or exit normally

wq! forced to save and exit
q! forced to quit
wq save and exit
q exit without saving

2.3 can not properly edit a file, edit the file there is always a message

The reason:
①. Not normally save and exit edit mode
②. Multiple users to simultaneously edit a file
Solution:
①. Delete temporary files rm .oldboy.txt.swp
②. Before resuming normal temporary file contents (vi -r oldboy.txt), delete temporary files
 

2.4 summary

normal situation:
vi oldboy.txt --i-- editor -: wq
①echo xxx > oldboy.txt.swp
②mv oldboy.txt.swp oldboy.txt
Error cases:
vi oldboy.txt --i-- editor - not saved
1. echo xxx > oldboy.txt.swp
Recovery information:
vi -r oldboy.txt
①cp oldboy.txt.swp oldboy.txt
 

3 important system files

Under 3.1 / etc directory of important documents

(1) NIC configuration file
File Path: / etc / sysconfig / network-scripts / ifcfg-eth0
① contents of the file:
TYPE = Ethernet --- specify the type of network
BOOTPROTO = none --- obtain IP address automatically obtain manner dhcp / manual configuration none (static static)
NAME = eth0 --- card name
DEVICE=eth0
ONBOOT = yes --- whether to activate the card
IPADDR = 10.0.0.201 --- IP address
PREFIX = 24 --- subnet mask
GATEWAY = 10.0.0.254 --- Gateway
DNS1 = 223.5.5.5 --- address of the DNS server
② load the file method:
systemctl start network --- start the server NIC
systemctl restart network --- all the servers in the network card restart
ifdown eth0 && ifup eth0 --- only the specified network card reboot (restart the enterprise network card method)
systemctl stop network --- network card Close
systemctl enable network --- implement the service at startup
systemctl disable network --- implement the service start Inhibit start
③ Expansion supplement: centos7
network operation and maintenance director of reference profiles systemctl restart network card
Referring nmtui NetworkManager operation and maintenance manager configuration information is preferably closed systemctl restart NetworkManager
 

3.2 DNS file

File Path: /etc/resolv.conf
document content:
nameserver 223.5.5.5 specify the DNS server address information
① file is loaded:
File configured, take effect immediately
The domain can not access the unusual problems to solve:
Modify the file resolv.conf DNS server address information, it will take effect immediately
Modify the network card configuration file, need to restart the server network card, network card configuration file overwrites DNS information DNS resolv.conf file information
② establish domain name + IP address correspondence / mapping relationship
Local Settings C: \ Windows \ System32 \ drivers \ etc \ hosts
Special server settings 8.8.8.8 114.114.114.114 223.5.5.5 --DNS server
 

3.3 Host name of the file

File Path: / etc / hostname
Host Name: City engine room _ _ _ Number service names cabinet
bj_jxq_03_web
 
centos6
View hostname: hostname
Modify the host name:
Temporarily modify: hostname oldboy-62
Permanent modification: vi / etc / sysconfig / network
 
centos7
View hostname: hostname
Modify the host name:
Temporary modifications: hostnamectl set-hostname oldboy-62 (even though the temporary modifications are permanently modified)
Permanent modification: vi / etc / hostname
 

4 Environment Variables

4.1 What is a variable: variable - the value of the contents of the book catalog books variables ---

oldboy (variable name) = 123456 --- set the variable
echo $oldboy -- 123456

4.2 set variables action: in the script will work

4.3 Script action: simplification will repeat

sh text.sh represents test.sh run the script sh: run

4.4 What is the environment variable:

The system already set variable
Environment variable names are generally composed of uppercase letters

4.5 System command works:

(1) ①mv command
② get the PATH environment variable information
③ to the appropriate directory to find the mv command file
④ command file can be found
⑤ execute command completion
echo $PATH 得到 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
(2) ①mv command
② get the PATH environment variable information
③ to the appropriate directory to find the mv command file
④ command File not found
⑤ file or directory does not exist
(3) Resolution:
Topic: mv / bin / mv / tmp
① absolute path to run the command
/tmp/mv /etc/hosts /tmp
② modify environment variables Information
Temporary modifications:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp
Permanent modifications:
vi / etc / profile
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp
export PATH=$PATH:/tmp
source / etc / profile or. / etc / profile for the changes to take effect profile
(4) requirements:
01. Create a directory oldboy
02. Create a directory oldboy.txt in oldboy
03. oldboy-62 edits in the document
04. The files are backed up oldboy.txt.bak
05. Back up files to the / tmp directory
①、mkdir /oldboy
touch /oldboy/oldboy.txt
echo oldboy-62 > /oldboy/oldboy.txt
cp /oldboy/oldboy.txt /oldboy/oldboy.txt.bak
mv /oldboy/oldboy.txt.bak /tmp
②,% s # oldboy # dddd # g Replace command
 

5 alias function

5.1 Role: simplify the complicated commands

cat /etc/sysconfig/network-scripts/ifcfg-eth0 == catnet
How to set up an alias:
①, temporarily set the alias
alias alias name = 'lawful command'
alias catnet='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
②, permanently set the alias:
vi / etc / profile
alias alias name = 'lawful command'
alias catnet='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
unalias cancel alias
 

6 supplement

1, export setting environment variables for modifying
2, source or Load configuration file immediately
3, alias View alias and modify the alias settings
4, unalias cancel alias function
5, hostname display the host name and host name modification
hostname -I display the address card information
6, systemctl for start / stop / restart services program
7, hostnamectl permanent and temporary modifications host name
8, ifup / ifdown control card designated start or stop
9, * means match all content
10 ,. hidden files
11, && represents the previous command is successful, then execute a command post
12, $ variable information call
It prompts the user to log in as an ordinary user
 
 
 

Guess you like

Origin www.cnblogs.com/basa/p/11115819.html