vi is a screen editor provided by all UNIX systems. It provides a window device through which files can be edited.
Basic concept of
vi Basically, vi can be divided into three operating states, namely Command mode, Insert mode and Last line mode. The functions of each mode are as follows:
1. Comand mode: Control the movement of the screen cursor, the deletion of characters or cursors, move and copy a certain section and enter the Insert mode, or to the Last line mode.
2. Insert mode: Only in Insert mode can you do text data input. Press Esc, etc. to return to Comand mode.
3. Last line mode: Save the file or leave the editor. You can also set the editing environment, such as searching for strings, listing line numbers, etc.
However, vi can be simplified into two modes, that is, the Last line mode is also included in the Command mode, and vi is divided into Command and Insert mode.
Basic operation of
vi•Enter vi.
After entering vi and the file name in the system prompt, you can enter the full-screen editing screen of
vi : $ vi testfile
One thing to pay special attention to is that you are in "Command mode" after entering vi. You must switch to Insert mode to enter text. Users who use vi for the first time will want to use the up, down, left, and right keys to move the cursor. As a result, the computer keeps calling and makes themselves half to death, so after entering vi, don't move around, and switch to Insert before talking.
• Switch to Insert mode to edit the file
. Press the'i','a' or'o' three keys in Command mode to enter the Insert mode. At this time you can start typing text.
i: Insert, insert the entered text from the current cursor position.
a: Increase, start inputting the next word where the cursor is currently.
o: Insert a new line and enter text from the beginning of the line.
•Insert switch→Command mode, press Esc.
You are currently in Insert mode, you can only keep typing. If you find a typo and want to use the cursor keys to move back and delete the word, you must press the ESC key to switch back to Command mode, and then delete the text.
•Leave vi and save the file
In Command mode, you can press the colon ":" to enter the Last line mode, for example:
:w filename (input "w filename", save the article in the specified file name filename)
:wq (input " "wq", because the file name testfile has been specified when entering, it will write testfile and leave vi)
:q! (Enter "q!" to force leave and abandon the edited file)
Command mode function key list
is introduced in the command mode command After the time, the function key with the word "commonly used" after the instruction indicates the more commonly used vi instruction. Readers must learn and remember.
(1) I, a, o switch into Insert mode. [Super Common]
(2) To move the cursor
vi, you can directly use the cursor keys on the keyboard to move up, down, left, and right, but the regular vi uses lowercase English letters
h, j, k, and l to control the cursor left, down, up, and right, respectively Move one grid.
Press Ctrl+B: the screen moves back one page. [Common]
Press Ctrl+F: Move the screen forward one page. [Commonly]
Press Ctrl+U: the screen moves backward half a page.
Press Ctrl+D: the screen moves forward by half a page.
Press 0 (number zero): move the beginning of the article. [Commonly used]
Press G: move to the end of the article. [Common]
Press w: the cursor jumps to the beginning of the next word. [Commonly used]
Press e: The cursor jumps to the end of the next word.
Press b: the cursor returns to the beginning of the previous word.
Press $: Move to the end of the line where the cursor is. [Common]
Press ^: Move to the first non-blank character in the line.
Press 0: Move to the beginning of the line. [Commonly used]
Press #: move to the #th position of the line, for example: 51, 121. [Commonly used]
(3) Delete character
x: delete a character after the cursor position each time. [Super Common]
#x: For example, 6x table deletes the 6 characters behind the cursor position. [Commonly used]
X: Large character X, each time you press it to delete a character in front of the cursor position.
#X: For example, 20X means to delete the first 20 characters at the cursor position.
dd: Delete the line where the cursor is located. [Super Common]
#dd: For example, the 6dd table deletes 6 lines of text from the line where the cursor is located. [Common]
(4) Copy
yw: Copy the characters from the cursor position to the end of the word to the buffer.
(I want to be the opposite of
#x, #X function) p: paste the characters in the buffer to the cursor position (commands'yw' and'p must be used together).
yy: Copy the line where the cursor is located. [Super Common]
p: Copy a single line to the place you want to paste. (The commands'yy' and'p' must be used together)
#yy: For example: 6yy means to copy 6 lines of text from the line where the cursor is located. [Commonly used]
p: Copy multiple lines to where you want to paste. (Commands'#yy' and'p' must be used together)
"ayy: put the copied line into buffer a, vi provides buffer function, which can store commonly used data in buffer
"ap: paste the data in buffer a.
"B3yy: save three lines of data into buffer b.
"b3p: paste the data in buffer b
(5) replace
r: replace the character at the cursor: [commonly used]
R: replace the character until you press Esc.
(6) Undo the last instruction
u: If you misuse an instruction, you can press u immediately to return to the previous operation. [Super Common]
.:. The last command can be repeated.
(7) Change
cw: change the word at the cursor to the end of the word $.
c#w: For example, c3w means to change 3 words.
(8) Jump to the specified line
Ctrl+G: List the line number of the line where the cursor is located.
#G: For example, 15G, means to move the cursor to the beginning of the 15th line of the article. [Commonly]
Introduction to commands in phpma open source Last line mode
Readers Before you want to use Last line mode, please remember to press Esc to make sure you are in Command mode, and then press the colon ":" or "/" or "?" Press one of the keys to enter Last line mode.
1. List line numbers
set nu: After entering "set nu", the line numbers will be listed in front of each line of the article.
2. Jump to a certain line of the article
#: The pound sign represents a number, enter the number before the prompt symbol ":" in Last line mode, and then press Enter to jump to that line, such as: 15[Enter] will jump to the article Line 15. [Commonly used]
3. Search for a character string
/keyword: press / first, and then enter the word you want to find. If the keyword you find for the first time is not as close to you as possible, you can keep pressing n until you find the keyword you want.
? Keyword: press first? , And then enter the word you want to find. If the keyword you find for the first time is not what you want, you can press n to find the keyword you want.
4. Replace string
1, $s/string/replae/g: Input "1, $s/string/replace/g" in the last line mode to replace the full text string with the replace string, where 1, $s is It means that the search interval is from the beginning to the end of the article, and g means that it is completely replaced without confirmation.
%s/string/replace/c: The string string in the full text will also be replaced with a replace string. The difference from the above command is that %s and 1, $s have the same function, and c means to replace the previous Must confirm again whether to replace.
1,20s/string/replace/g: replace the string between 1 and 20 with the relpace string.
5. Save file
w: Press w before the last line mode prompt symbol ":" to save the file. [Super common] phpma open source
#, # w filename: If you want to extract a certain paragraph of the article and save it as another file, you can use this command # to represent the line number, for example, 30,50 w nice, to set the first part of the article you are editing 30-50 lines are saved as nice file.
6. go away
q: Press q to leave. Sometimes if you cannot leave vi, you can use "!: Forced to leave vi, such as "q! "
Qw: It is generally recommended to use it with w when you leave, so you can save files when you leave. [Common]
XSHELL commonly used commands
Commonly used commands:
suse linux common commands
(1) Command ls-list files
ls displays the current directory file
ls -la gives a long list of all files in the current directory, including "hidden" files starting with a period
ls a* lists all files in the current directory beginning with the letter a
ls -l *.doc gives all files ending with .doc in the current directory
(2) Command cp-copy files
cp afile afile.bak copy the file as a new file afile.bak
cp afile /home/bible/ Copy the file afile from the current directory to the /home/bible/ directory
cp * /tmp Copy all unhidden files in the current directory to the /tmp/ directory
cp -a docs docs.bak Recursively copy the docs directory in the current directory to the new directory docs.bak, keep the file attributes, and copy all files, including hidden files starting with a period. For convenience, the -a option includes the -R option
cp -i ask the user before overwriting
cp -v tells what the user is doing
cp -r
(3) Command mv-move and rename files mv aflie bfile rename afile to bfile
mv afile /tmp Move afile in the current directory to the /tmp/ directory
(4) Command rm-delete files and directories rm afile delete file afile
rm * Delete all files in the current directory (files not hidden). The rm command does not delete directories unless the -r (recursive) parameter is also specified.
rm -rf domed delete the domed directory and all the contents it contains
rm -i a* Delete all files in the current directory starting with the letter a, and prompt the user for confirmation each time they are deleted
(5) Command cd-change directory
cd switch to the home directory
cd ~ switch to the home directory
cd /tmp switch to directory /tmp
cd dir switch to the dir directory under the current directory
cd / change to the root directory
cd .. switch to the upper level directory
cd ../.. switch to the upper level directory
cd ~ switch to the user directory, such as root user, switch to /root
(6) Command mkdir-create a directory
mkdir phots creates a directory named photos in the current directory
mkdir -p this/that/theother creates the specified nested subdirectory in the current directory
(7) Command mkdir-delete directory
mkdir will delete empty directories
(8) Command more, less-view file content
more /etc/passwd View the contents of /etc/passwd
Function: paging display command
more file
The more command can also be used with other commands through the pipe character (|), for example: ps ux|more ls|more
less /etc/passwd View the contents of /etc/passwd
(9) Command grep-search file content
grep bible /etc/exports Find all lines containing bible in the file exports
tail -100 /var/log/apache/access.log|grep 404 Find the line containing "404" in the last 100 lines of the WEB server log file access.log
tail -100 /var/log/apache/access.log|grep -v googlebot In the last 100 lines of the WEB server log file access.log, look for lines that are not accessed by google
grep -v ^# /etc/apache2/httpd.conf In the main apache configuration file, find all non-comment lines
(10) Command find-find file
find .-name *.rpm Find the rpm package in the current directory
find .|grep page Find files with file name containing page in the current directory and its subdirectories locate traceroute Find files with file name containing traceroute anywhere in the system
(11) Command vi-edit file
gvim open program
vi /etc/bubby.txt Edit the file /etc/bubby.txt with vi
vim /etc/bubby.txt Edit the file /etc/bubby.txt with vi
Quick operation:
Switch window: alt+1,alt+2
Full screen: alt+Enter
Suspend vim (pause): ctrl+z, you can perform other shell operations after pausing, and then you can switch back to the vim interface to continue editing with the fg command
:MR: View historical file records (Note: MR is capitalized)
:sp switch interface window horizontally
:vsp Switch the interface window vertically to facilitate multi-file comparison and encoding (as shown below:) emacs /etc/bubby.txt Edit the file /etc/bubby.txt with emacs
(12) Command rz, sz-file upload and download
Run the command Sudo rz to receive the file, and xshell will pop up a file selection dialog box. After selecting the file, close the dialog box and the file will be uploaded to the current directory in linux.
Running the command Sudo sz file is to send files to windows (the saved directory can be configured) is much more convenient than the ftp command, and the server does not need to open the FTP service.
(13) Command cat-display file content
cat file
(14) Command ps-view process ps [options]
DESCRIPTION: The ps command displays some information about the options of the running program. If you want to display some repeated information about the options, please use the top command instead.
Use standard syntax to view every process on the system.
ps -e
ps -ef
ps -eF
ps -ely
(15) Command kill-kill the process
[root@linux ~]# kill -signal %jobnumber
[root@linux ~]# kill -l
parameter:
-l: This is the lowercase letter of L, which lists the signals currently available for kill? There are 62 signals in total.
signal: What kind of instructions should be given to the next job! Use man 7 signal to know:
-1: Re-read the parameter setting file (similar to reload);
-2: Represents the same action as inputting [ctrl]-c from the keyboard;
-9: Force delete a job immediately;
-15: Terminate a job in a normal procedure. It is not the same as -9.
Example 1: Find out the background work in the current bash environment and delete the work.
[root@linux ~]# jobs
[1]+ Stopped vim bashrc
[root@linux ~]# kill -9 %1
[1]+ Vim bashrc has been cut
(16) Command stop, start-restart tomcat
./catalina.sh stop
./catalina.sh start
(17) Command top-view cpu, memory
(18) Command pwd-view current path
(19) Command tar-pack, unpack rar
tar -cvf **.tar a.jsp b.java Type a and b into **.rar
tar -xvf **.tar a.jsp b.java unpack **.tar
(20) Command tail-view file details
tail -f aaa.txt to see the detailed information of the aaa.txt file
tail -n x aaa.log x: the last few lines
(21) Command head-view the name and suffix of the file
head -n x aaa.log x: the first few lines aaa.log: the name and suffix of the file to be viewed
(22) Command diff-compare file contents
diff dir1 dir2 compares whether the file list of directory 1 and directory 2 are the same, but does not compare the actual contents of the files, and lists the differences
diff file1 file2 compares whether the contents of file 1 and file 2 are the same. If it is a text format file, the different contents will be displayed. If it is a binary code, it only means that the two files are different
comm file1 file2 compares files and shows the differences between the two files
(23) Command ln-establish a connection
ln source_path target_path hard link
ln -s source_path target_path soft connection
(24) Command touch-create an empty file
touch aaa.txt creates an empty file, the file name is aaa.txt
(25) Command man-view the help of a command
man ls displays the help content of the ls command
(26) Command w-display detailed information of the logged-in user
Sarge:~# w
(27) Command who-display logged in users
Sarge:~# who
(28) Command last-view the recent users who have logged into the system
Sarge:~# last
(29) Command date-system date setting
date -s "060520 06:00:00" sets the system time to 6 o'clock on May 20, 2006.
(30) Command
clock——clock setting
clock -r reads the time parameter in the system Bios
clock -w write the system time (such as the time set by date) into Bios
(31) Command uname-view system version
uname -R displays the version of the operating system kernel
(32) Command reboot, shutdown-shut down and restart the computer
reboot restart the computer
shutdown -r now restart the computer, restart the computer after stopping the service
shutdown -h now shut down the computer, shut down the system after stopping the service
halt shut down the computer
Shutdown -r now is generally used to shut down related services when restarting the system, as is shutdown -h now.
(33) Command su-switch user
su-switch to root user
su – zhoulj switch to user zhoulj,
Note:-, he is very important, using -, will use the user's environment variables
(34) Command free-view memory and swap partition usage
Sarge:~# free -tm
(35) Command uptime——The current time, the elapsed time since the system started up and running, the number of connected users, the system load of the last minute, five minutes and fifteen minutes
Sarge:~# uptime
(36) Command vmstat-monitor virtual memory usage
# vmstat
(37) Command iostat-disk throughput
-c only display the CPU line
-d show disk line
-k displays disk output in kilobytes
-t include a timestamp in the output
-x includes expanded disk metrics in the output
(38) Command clear-clear screen
clear
(39) Restart tomcat
(40) Change user chown
Change the owner or group of a file or directory chown -R -h owner file
-The R (recursive) option means that the same operation is performed on the files in all subdirectories.
The-h option means that changing the owner of a symbolic link file does not affect the target file pointed to by the link
chown -R xh test1 (all files in the test1 directory and subdirectories become xh)
1. View the process number of the process to be restarted
Ps –ef|grep xxxx
2. Kill the process of the project
Kill the second column first, then the first column
Sudo kill -9 x x
(x is the process number, killing multiple at the same time separated by spaces)
3. Restart tomcat
First find the bin directory of tomcat Cd tomcat/bin;
Then run sudo ./run.sh to start tomcat.
Maven package statement: mvn clean package –Dmaven.test.skip=true