Linux-vi Editor 3

Source: Internet
Author: User
Tags readable

1. Open File
> VI file//This mode is command mode

2. Tail-line mode operation
>: Q//This mode is "tail line mode"
>: w//Save the modified document
>: wq//Save and exit
>: q!//forcibly quits without saving changes
>:/content//To find the specified content, "n" will find the next, "N" will find the previous
Finds the end of the document and then runs to the beginning of the document
>: Set number/nu//sets a number for each line of the file
>: Set Nonumber/nonu//Cancel numbering setup
>:%s/bin/abcd///Replace all rows with the bin content as ABCD
>: s/bin/abcd///Replace the first occurrence of the current line with the bin as ABCD
>: s/bin/abcd/g//replaces the current line all the bin is ABCD
>: n//cursor jumps to n-line position
>/content//Find specified content


3. Command Mode mouse movement
Character movement: Top, bottom, left, right keyboard
H (left) J (bottom) K (UP) L (right)

Word Move W: The first letter of the next word
B: The first letter of the word or the last word
E: The end letter of the word or the next word

Row-level Move $: reach end of line
0: Number 0 arrives at the beginning of the line

Paragraph-level movement {: paragraph header
}: Tail of paragraph

Screen-level movement L: the tail of the screen (the current screen, it does not go to the next screen)
H: Screen Header

Document-level Move G: Document trailer
1G: First line of document
NG: Cursor goes to Nth line


4. Command mode Delete Document information

Character-level Delete X
Universal Delete d+ cursor Movement distance
d+$ Delete from current position to end of line
D+0 from a single front position to the beginning of the line
D+w Delete words (including spaces behind words)

D+} to the end of the paragraph (trailing blank lines are reserved)
d+{Delete to the header of the paragraph (the empty line at the top of the header is also deleted, deleting only one row of blank lines)

D+l Delete to the end of the screen, delete include when forward
D+h Delete to screen header, delete include when forward

D+g Delete to the end of the document, delete include when forward
D+1G Delete to document header, delete include when forward
D+ng Delete to the nth row of the document, deleting the current and nth rows

DD Delete When moving forward
N+DD Delete n rows from the current row


5. Copy and paste the command mode
YY Copy a single line
N+YY Copy N rows
y+ cursor movement distance can be flexibly copied [this way use can refer to delete]
P Paste (start pasting behind the cursor position, [the following row of the cursor])

6. Deleted content, can also be pasted, deleted content is placed in the cache, you can also provide paste service


7. Undo the operation in "command mode"
U//Undo, will recursively undo all previous operations
r+ character//single character substitution
. Point, repeat the last command
J//Merge two lines

8. The color of the modified directory is "gold"
Edit File Vi/etc/dir_corlors

linux-Common Commands

1. See what files and directories are in the current directory
> ls//list
> Ls-al//all list Displays the full file details of the current directory (shown as a list) shows hidden files
> ls-l//list Displays the details of the current directory general file (shown in a list)
> ls-a//Display the current directory full file information, only the name of the file
> ls directory//listing file information for the specified directory
> ll//Lists the details of the current directory file as a list (hidden files are not displayed)

2. See which directory I am currently in
>pwd

3. Display current User information
>who am I//display user name and time information of their login system
>whoami//Display only user name information for the currently logged on system

4. Switch from normal user to root user
> Su-//Prompt to enter a password
> su root//
Two switching modes: The former switch to Super Administrator user, the permissions are Super Administrator privileges
Although the latter switch to Super Administrator, whose permissions are normal permissions

5. Switch from root user to normal user
> su Shuhua//cut back from root to normal user

6. Switch from the desktop window to "Command line window" (Switch with Super Administrator)
> Init 3
> init 5//Switch back from "command line" to "desktop"

7. Directory Switching
> CD Specific directory

8. Output file information, all content directly output
>cat file

9. Create Directory Directives
> mkdir Catalogue
> MKDIR-P Catalog 1/Directory 2/Directory 3//recursively Create directory

10. Modify the name of the directory
> MV Catalogue 1 Catalogue 2//Change the name of "Directory 1" to "Directory 2"
> MV Directory/directory a directory/directory B//change "directory A" to "Directory B"

11. Move operation
> MV Files directory//move files to the specified directory
> MV Directory directory//move directory to the specified directory (including multi-level directories)

When the MV instruction is moved, when is the name
MV One-parameter two ginseng
The two arguments do not exist, it is to change the name
The second parameter is the existence of the directory, is the mobile

MV Com.txt Red.txt
Red.txt is a file that exists, Com.txt is also a file that exists
First clear, no move operation is possible
No
"Can" change the name from Com.txt to Red.txt

MV Guangzhou hello.txt
Guangzhou is a directory of existence
Hello.txt is a file that exists
First clear cannot move
Is it possible to change the name of Guangzhou to Hello.txt
"Cannot" change the name from "Guangzhou" to "Hello.txt"
Yes

13. Deleting a directory
> rmdir directory//delete a single directory (no sub-directories)
> RM-RF file name//force forced recursive recursive delete
> RM-RF///kill your self [root user can delete more files]
> RM-RF shanghai/beijing//This is to delete the Beijing directory below Shanghai and will not delete Shanghai

14. Copying
>CP Copy
>CP Directory Address-r//copy directory need to add fixed parameter-r, directory will be replicated recursively
>CP file directory/non-existent name//file is "renamed" while being copied to the specified directory
>CP File New file name//copy and start a new name

15. View the contents of a file
> more File//from the first line of the file content, display content view%
Hitting Enter will view the contents of the back row by line, and the cursor will be released at the end.
> Less files//line-by-row display of file contents, with "Up, down, left, right" to view parts of a document
Allow forward viewing, no percent display
Releasing the cursor with the "q" key
> head-n File//view the first n rows of a file
> tail-n File//view file at the end of N-line content
> WC file//Calculate file content line number, paragraph

16. Create a new file
> Touch file name//create file

17. Add content to a file
> Echo Content > File//Enter the specified content into "file"
> Echo content >> File//append content to file inside

18. redirect content to a file
> Cat file 1 > File 2//redirect the contents of file 1 to file 2 inside, file 2 is not automatically created
> Cat files 1 >> files 2//chasing heavier orientations

19. Add User information (group number, home directory) of/ETC/PASSWD storage System
> Useradd User Name
> USERADD-G number username//Add user's simultaneous set "group number"
> useradd-d directory Username//Add user to set "home directory", directory is not automatically created
> useradd-g number-D home directory user name//set group number and home directory address at the same time
> USERADD-G Group number users//common operations

20. Create a group (you can set the group itself number)
> Groupadd Group name//common operation
> groupadd-g Number Group name//You can set the group number, the next group number from the largest self-increment

21. Modify user Information (group number, home directory address, user name)
> usermod-g Group number User name//modify group number of the user
> usermod-d Home Directory Username//Modify the user's home directory, passwd file has been modified, actually does not have this directory (manually created)
> usermod-u number User name//modify the user's own number
> usermod-l new name old username//modify user's name

22. Modify Group (group number, group name)
> groupmod-g Group Number Group name//modify group number
> groupmod-n New group name old group name/modify Group name

23. Delete User (user information, home directory address)
> Userdel Users
> Userdel-r user//delete user at the same time, its "home directory" address will also be deleted

24. Delete a group
> Groupdel Group name//a group below a specific user, the group is not allowed to delete


25. See what parameters can be set when a command is used
> Useradd--help Command--help

26. Set a password for a user (you can log in to the system)
> passwd username//Password Enter two times as prompted

27. View command-specific parameter settings
> Man command//back-and-forth view of command usage parameters

28. Setting permissions for a file [relative mode]
> chmod u+x file
> chmod g+x File//Set execution permissions for the same group of users
> chmod o+x File//Set execution permissions for other groups of users
> chmod o+w,o+x File//simultaneous write to file, select all

> chmod u-r File//Cancel owner's readable permission
> chmod g-w,g-x File//Cancel the same group of user write, execute permission
> chmod o-r,o-x File//Cancel other group user Read, execute permissions

> chmod g+rx,o+wx File//To file the same group of users set "read, execute" permissions, other groups of users have "write, execute Permissions"
> chmod U-RWX,G-RW//cancellation of specific user rights

29. Digital [Absolute mode] Set file permissions
Read, write, and execute
Binary code represents the computer's information
1-------------1
Ten-------------2
-------------4

For example: read: 1 write: 2 Execute 3
If file permissions are read-write, there is a number 6.
If the file is read-only permission is the number 1
3 do not know whether it is "read-write" or "execute permission", ambiguous generation

The correct usage is: Read 4 Write 2 execute 1
1: Execution
2: Write
3: Write, execute
4: Read
5: Read, execute
6: Read and Write
7: Read, Write, execute
> chmod 777 File//host, same group of users, other group user rights are full
> chmod 001 File//host, same group of users do not have permissions, other groups of users have the ability to execute
Ppink.txt Master has to write, execute the same group of users have read other group users have read, execute
> chmod 345 ppink.txt

30. Set permissions for directory recursion
> chmod 755 Directory-r//-r parameter can be recursively directory for permission settings

31. Use of File permissions
-w-file only writable permission [can not see the original content, can write, overwrite write, forcibly save]
r--file has only read permission [can see the original content, can write, will not overwrite, forcibly save]
--x file has executable permissions [can not see the original content, can write, overwrite write, forcibly save]

32. Directory Permissions
r--directory has readable permission [can read inside the file, not allowed to enter]
--x directory has execute permission [cannot read, write not allowed, allow access to directory]
-w-directory Some permissions [cannot read, cannot increase or decrease the file, cannot enter the directory]
rw-read, write access [can read, cannot enter directory]
RWX read, write, executable [can read, can increase the reduction of documents, can enter]
How a directory is written: Adding files to a directory or reducing files is writing

33. Operation of the same group of users on file permissions
r--operations read-only files [can be read, can be written, forcibly saved, file owners and groups have changed]
-w-Write permission [cannot read, can forcibly overwrite write, file owner and group has changed]
--x whether the directory can be accessed

[A directory has executable permissions, indicating that the user can switch into the directory]

34. The various permissions of the file or directory have no effect on super Administrator root

35. Find what we need in the specified file
> grep content Files

36. View the Task Manager
> Top

37. View memory Information
> free-m//Display memory size usage in M-Gigabit units

38. View the size of a file or directory
> du-h target//with minimum unit limit (4k) 1 bytes

39. File Search
Find directory option option value
> Find/-name abc.txt//Locate this file with the name Abc.txt in the current directory
> Find/-name XXX//Locate files in the root directory
> Find./-size Size//Depending on the size of the file
Unit:
10 512 bytes Default
100C 1 byte units
100k 1024 Byte units
> Find/-size +100c//Find file size larger than 100 bytes
> Find/-size-100c//Find files smaller than 100 bytes in size
> Find/-size 4//Find files of size equal to 2048 bytes
> Find/-size 2k//Find files of size equal to 2048 bytes

> Find/-maxdepth 1//Find file directory deepest is level 2
> Find/-mindepth 1//Find files to find by the lightest level

> Find/-type F//Search by type, find file type
> Find/-type D//Search by type, find directory type

> Find/-user username//Find file owner for xx file
> Find/-UID User number//Find file owner number xx
> Find/-nouser//Find files with no master
When a file is created, it is created by a user
Some files are created and then posted to the top of the network by the user.
We download the Web files locally and put them in our own system.
The user who created the file is not in my own system.
For example, the user number that created this file is 710 (user name: RUNFA)

> Find/-perm Permissions 764//Search based on file permissions

> Find/-name ' bao* '//For Fuzzy Lookup, name prefix is bao file

40. Setting up a soft connection
> ln-s source File Link file
> Ln-s/home/shuhua/shanghai/passwd/var/passwd

41. View the file index number
> Ls-li

42. Making Task Scheduling instructions
> CRONTAB-E//Edit Task scheduling instructions
> crontab-l//View task Scheduling command settings
To execute a specific mission at 17:38.
Minute hour date Month Week specific command
* * * */home/shuhua/shanghai/newout.sh

0 on behalf of Sunday

43. Set the system time
> date-s "2013-08-13 17:39:40";
> date//Viewing system time

44. Set the owner for the file
> Change Owner
> Chown Master File

45. Set up a group for a file
> Change Group
> CHGRP Group files

> chown. Group files

46. Also set the host and group for the file
> Chown Master. Group files
> Chown Master. Group Directory-r//recursive to directory settings host and group information, level two directories and level three directories, etc. will be set

Linux-vi Editor 3

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.