Vim usage and process management in Linux

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.