Vim: Text editor vim file name vim + n (row number) such as vim + 3/etc/passwd cursor in the third line; +/word cursor in the first line of the word; vim has three modes: Command, input, and last line. command modes & mdash; & gt; input mode...
Vim: text editor
Vim file name
Vim + n (row number) such as vim + 3/etc/passwd cursor in the third line;
+/The word cursor starts with a line in the word;
Vim has three modes:
Command, input, and last line modes
Command mode-> input mode
1) I I
2) a
3) o O
4) c C
Command mode-> last line mode
:
In command mode: Move the cursor: h (left), l (right), k (top), j (bottom)
Jump between words: w the beginning of the next word
E. end of the next word
The first word of B.
Jump between the beginning and end of a line: ^ (first of a non-empty line), 0 (first of a blank line)
$ (The last character of this line)
Inter-sentence jump:) the beginning of the next sentence;
Inter-segment jump:} The first segment of the lower segment; {the first segment of the upper segment
Line jump: nG or: n jump to line n; G jump to line n;
1G jump to the first line;
Ctrl + f flip the screen down; crtl + B flip the screen up;
Ctrl + d flip down half screen; ctrl + u flip up half screen;
Edit command:
X: Delete a character, such as d dd, dw, de, db, d), and d $, to the position positioned by the cursor. The deleted content is not cleared immediately, but saved in the buffer zone.
P: paste;
Y: copy;
U: undo the last operation. U: undo all the operations of the previous operation. ctrl + r: undo
.: Redo;
Search and replace command: s // gi s indicates search replacement; g indicates global replacement; I indicates case-insensitive
Configure vi and vim
Dynamic Configuration: set (list a small number of important configuration items) or set all (list all configuration items)
: Set number to set the row number;: set autoindent (ai) Auto Indent
: Set ignorecase (ic) ignores case sensitivity;: set nowrap does not split rows for display
Syntax enable on, off, enable, clear Syntax coloring.
If it is canceled, set no [], for example, set noai
Permanent configuration :~ /. Vimrc or ~ /. Exrc
To save these configurations, you can use them each time you start the editor. you need to place the commands for those configuration items in ~ /. Vimrc file. If the file does not exist, vi and vim will read the older ~ /. Exrc file.
In vi, we can also split the screen. in the last line mode, input: split, or ctrl + w, s to split the screen horizontally;
Ctrl + w, v vertical split the screen; ctrl + w, direction keys will switch in the window
When we split not one file but multiple files: vim + o 1. diff 2. diff split two files horizontally; + O vertical split view we can also use ctrl + w, direction key.
When we use vim 1 .. diff 2. when diff is enabled, 1 is displayed first .. diff and then input next in the last line mode will display 2 .. diff; previous will display 1. diff; last displays the last file; first displays the first file;
When exiting, we use qall to close all;
What is a process?
A process is a set of commands loaded into the memory.
In a Linux system, when an event is triggered, the system will define it as a process and give the process an ID, called PID. based on the user-related property relationship of the process, set valid permissions for this PID. The Linux kernel tracks all aspects of the process through the process PID. the running information is located in the/proc directory, where the process number is generated in 1--32767. Process 1 always belongs to the init process. Because init is the first process when you start linux. Other processes are derived from her child processes. Child processes are derived from parent processes. We can use the command "pstree" to view the generated process.
Core functions: memory management, process management, hardware management, cpu management, and file system management.
View process information (ps) a including all terminal processes;
There are two processes in the system: User process (terminal process); daemon process (running when Linux is started)
X: displays the daemon process, not the terminal process;
U displays the information of the process owner who initiated the process.
O display custom information such as pid tty
-E: show all information (= ax)
-F displays the complete format information, such as ps-ef.
Pid process number
Command that started the process
% Cpu usage
% Men memory usage
State Process State D (non-interrupting sleep) R (running) S (sleeping) T (stopped) X (dead) <(high-priority process) N (low-priority process) L (locked in memory) Z (zombie) l (multi-thread) + (program running on the foreground) start (process start time)
Tty
Euser effictive user name
Ruser initiator
Vmemory occupied by Vsz
Rss non-virtual memory size
Time used by cpu accumulation Time
We can also use ps aux | grep x to display specific processes.
Pgrep supports regular expression commands
Pgrep-U root
-G student
Pgrep-l 1; pgrep-U root-v reverse display;
Press the exact program name: pidof such as pidof bash
Signal of communication between processes; common signal,
Signal 15, term (default) untidy termination
Signal 9, kill immediate termination
Signal 1, hup re-reading configuration file
We can use man 7 signal to display the complete list;
Send signals to processes
By PID: kill pid such as kill 3428
By name: killall comm such as killall httpd
By Mode: pkill pattern disables some matching processes
The scheduling priority determines the CPU usage:
Priority is affected by the Nice value of the process. The value range is-20 to 19. the default value is 0! The smaller the value, the higher the cpu usage.
We can change the scheduling priority value:
When starting the process: nice-n 5 command (such as ifconfig)
After starting: renice 5 PID, such as renice 15-p PID
Only the root user can reduce the nice value (improve its priority), and normal users can only increase the nice value.
View nice values: ps axo pid, nice
Displays real-time process information and top commands for dynamically viewing process information
Top is refreshed every 5 seconds by default.
# Top
Cpu (s) 0.0% us (user-initiated process) 0.1% sy (system-initiated process) 0.0% ni (% of nice value modification) 99.4% id (cpu idle rate) 0.0% wa (cpu wait) 0.0% hi (hardware interrupt) 0.0% si (soft interrupt) 0.0% st (time stolen by virtual machine)
Top-B-n 2
Run the process in the background: add &
Pause a running process: use ctrl + z or send a signal 17 (stop)
Manage background processes and pause processes
List the number and name of a process: jobs-l and the process number:-r only lists jobs in the running state;-s only lists jobs in the stopped state.
Run bg % job number in the background; % can be omitted
Run: fg % job number on the foreground;
Sending signal: kill-[signal] [% job number] % cannot be omitted
One-time running process use at (use mail to check that the created process has been completed), and repeated running use crontab
At time creation use ctrl + d to end crontab-e
-L list crontab-l
-C job number details
-D job number: delete crontab-r
Crontab includes the following sections:
Min hour day month week-day command
For example, *** echo "how are you !"
Send messages at and each day
Files written with crtontab are saved in/var/spoo/cron /.
To make up for crontab's 24-hour online disadvantage, anacron can be used to execute jobs that are not executed after being started.
Trap captures signals such as trap "do not interrup me !" INT (ctrl + c)
Environment variable
Path command search Path
Declare bad environment variables: export A or declare-x
Some common variables
The Ps1 variable sets the prompt. by default, common escape sequences include:
\ H host name; \ u user name; \ w current working directory; \ $ if the root user is displayed #, if the common user is displayed $.
Alias (aliase)
For example, alias dir = 'ls-L'
Unalias alias revocation
\ Rm is required if you want to use the rm command instead of its alias.
For example, alias rm = "rm-I"
\ Rm-r junk
Logon shell and non-logon shell
A logon shell is a shell started after a user logs on to the system. A non-logon shell is a shell started in other ways. it may be started after the user or program issues a bash command.
Bash start task: profile
Saved in the/etc/profile File (global) and ~ /. Bash_profile File (user)
Run only for the logon shell.
Used to set environment variables and run commands (such as mail check program scripts)
The/etc/profile shell script is the first startup script to run after the login shell starts. it runs only for the login shell. non-login shell does not reference this script.
Log on to the shell and first call the/etc/profile file, which calls/etc/profile. d. Then ,~ /. Bash_profile is called.
Bash start task: bashrc
Stored in the/etc/bashrc file (global) and ~ /. Bashrc file (user)
Run for all shells
Used to set local variables and define aliases.
Bash exits the task
Save in ~ /. Bash_logout File (user)
Run when you exit the shell logon.
Used to create automatic backup and clear temporary files.