Linux-vi Editor 3: linuxvi Editor

Source: Internet
Author: User

Linux-vi Editor 3: linuxvi Editor

1. open the file
> Vi file // This mode is the command mode

2. Tail row operation
>: Q // This mode is "tail mode"
>: W // Save the modified document
>: Wq // save and exit
>: Q! // Force exit without saving the changes
>:/Content // find the specified content. "n" searches for the next one, and "N" searches for the previous one.
// Find the end of the document and run it to the beginning of the document.
>: Set number/nu // set the number for each row of the file
>: Set nonumber/nonu // cancel the number setting
>: % S/bin/abcd // Replace the bin content of all rows with abcd
>: S/bin/abcd // Replace the first bin of the current row with abcd.
>: S/bin/abcd/g // replace all the bins in the current row with abcd.
>: N // jump to n rows with the cursor
>/Content // find the specified content


3. Move the mouse in command mode
Character movement: upper, lower, left, and right keyboards
H (left) j (bottom) k (top) l (right)

W: The first letter of the next word.
B: The first letter of the current or previous word.
E: The ending Letter of the current or next word

Row-level movement $: at the end of a row
0: The number 0 reaches the beginning of the line.

Paragraph-level movement {: paragraph Header
}: End of a paragraph

Screen-level mobile L: The end of the screen (the current screen will not go to the next screen)
H: screen Header

Document-level moving G: End of the document
1G: first line of the document
NG: cursor goes to line n


4. Delete document information in command mode

Character-level deletion x
General Deletion d + cursor moving distance
D + $ Delete from current position to end of line
D + 0 delete from the front position of a ticket to the beginning of a row
D + w delete words (including spaces behind words)

D +} Delete to the end of the paragraph (empty lines at the end are retained)
D + {Delete to the first part of the paragraph (the empty rows above the first part are also deleted, and only one blank row is deleted)

D + L Delete to the end of the screen, including the current row
D + H Delete to the screen header, including the current row

D + G Delete to the end of the document, including the current row
D + 1G Delete to the Document Header, including the current row
D + nG: Delete row n of the document. Delete rows including current and n.

Dd deletes the current row
N + dd Delete n rows from the current row down


5. copy and paste in command mode
Yy copy a single row
N + yy copy n rows
Y + the moving distance of the cursor can be flexibly copied. [for this method, refer to delete]
P paste (start to paste behind the cursor position, [the last line of the row where the cursor is located])

6. The deleted content can also be pasted. The deleted content can be stored in the cache, And the paste service can also be provided.


7. Undo the operation in "command mode"
U // undo. All previous operations are recursively revoked from the upstream
R + character // replace a single character
. // Point, repeat the previous command
J // merge two rows

8. Change the directory color to "golden"
Edit the vi/etc/DIR_CORLORS File

Linux-Common commands

1. view the files and directories in the current directory
> Ls // list
> Ls-al // all list: displays the details of all files in the current directory (displayed in list form). Hidden Files are displayed.
> Ls-l // list displays the details of the general files in the current directory (displayed as a list)
> Ls-a // display all file information in the current directory, only the file name
> Ls directory // list the file information of the specified directory
> Ll // list the details of the current directory file (hidden files are not displayed)

2. view my current directory
> Pwd

3. display current user information
> Who am I // displays the user name and the time when the user logs on to the system.
> Whoami // only displays the User Name of the current logon System

4. switch from a common user to a root user
> Su-// The system prompts you to enter the password.
> Su root //
Two switchover modes: the former is the Super administrator user, and the permission is also the super administrator permission.
Although the latter is switched to a super administrator, its permissions are normal permissions.

5. Switch from root user to normal user
> Su shuhua // switch from root to normal user

6. switch from the desktop window to the command line window (through the super administrator switch)
> Init 3
> Init 5 // switch from "command line" to "desktop"

7. Directory Switching
> Cd directory

8. output file information. All content is output directly.
> Cat files

9. create directory commands
> Mkdir directory
> Mkdir-p directory 1/directory 2/directory 3 // recursively create directory

10. Modify the directory name
> Mv directory 1 directory 2 // change the name of "directory 1" to the name of "directory 2"
> Mv directory/directory a directory/directory B // change "directory a" to "directory B"

11. Mobile Operations
> Mv file directory // move the file to the specified directory
> Mv directory // move the directory to the specified directory (including multi-level Directories)

12. When is the mv command moved or its name?
Mv one parameter and two parameters
The two parameters do not exist, that is, change the name.
The second parameter is an existing Directory, that is, moving

Mv com.txt red.txt
Red.txtis the existing file, and com.txt is also the existing file
First, it is clear that the operation cannot be moved.
No
You can change the name from com.txt to red.txt.

Mv guangzhou hello.txt
Guangzhou is an existing Directory.
Hello.txt is an existing file
First, it is clear that it cannot be moved
Modify the name of guangzhouto hello.txt
[No] Change the name from "guangzhou" to "hello.txt"
Yes

13. delete a directory
> Rmdir directory // delete a single directory (no sub-directory)
> Rm-rf file name // force recursive Deletion
> Rm-rf // kill your self [the root user can delete more files]
> Rm-rf shanghai/beijing // This is to delete the beijing directory under shanghai.

14. Copy
> Cp copy
> Fixed parameters must be added to the cp directory address-R // copy directory. The directory will be recursively copied.
> Cp file directory/name does not exist // The file is "renamed" when it is copied to the specified directory"
> Cp file new file name // copy and new name at the same time

15. View File Content
> More file // display the content starting from the first line of the file content. % of the displayed content is displayed.
// Press enter to view the following content line by line and release the cursor at the end.
> Less file // display the file content line by line. You can view the content of each part of the document through "top, bottom, left, right ".
// Allows forward viewing. No percentage is displayed.
// Release the cursor through the q key
> Head-n file // view the content of the first n lines of the file
> Tail-n file // view n lines at the end of the file
> Wc file // calculate the number of lines and paragraphs of the file content

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

17. add content to the file
> Echo content> file // enter the specified content into the file
> Echo content> file // Append content to the file

18. Redirect content to a file
> Cat file 1> file 2 // redirects the content of file 1 to file 2. If file 2 does not exist, it is automatically created.
> Cat file 1> file 2 // append redirection

19. Add User/etc/passwd to store system user information (group number and home directory)
> Useradd User Name
> Useradd-g ID username // Add a user and set "group ID"
> Useradd-d directory name username // Add a user and set "home directory". The directory is not automatically created.
> Useradd-g no.-d home directory username // set the group ID and home directory address at the same time
> Useradd-g group number user // Common Operations

20. Create a group (you can set the group ID)
> Groupadd group name // Common Operations
> Groupadd-g no. group name // you can set the group number. The number of the next group must be auto-incremented from the maximum.

21. Modify user information (group number, Home Directory address, and user name)
> Usermod-g group ID username // modify the user group ID
> Usermod-d home directory username // modify the user's home directory. the passwd file has been modified, but this directory does not exist (manually created)
> Usermod-u ID username // modify the user ID
> Usermod-l new name old user name // modify user name

22. Modify the group (group ID and group name)
> Groupmod-g group no. group name // modify group no.
> Groupmod-n new group name old group name // modify group name

23. delete users (user information, Home Directory address)
> Userdel user
> Userdel-r user // When deleting a user, its "home directory" address will also be deleted

24. delete a group
> Groupdel group name // a specific user under a group, which cannot be deleted


25. Check the parameters that can be set when a command is used.
> Useradd -- help Command -- help

26. Set a password for a user to log on to the system)
> Passwd user name // enter the password twice as prompted

27. view the specific parameter settings of the command.
> Man command // view command parameters repeatedly

28. Set permissions for files in [relative mode]
> Chmod u + x file
> Chmod g + x file // set the execution permission for users in the same group
> Chmod o + x file // set the execution permission for other group users
> Chmod o + w, o + x file // At the same time, you can set the writable and executable option for the file

> Chmod u-r file // cancel the master's read permission
> Chmod g-w and g-x Files // cancel the write and execution permissions of users in the same group
> Chmod o-r and o-x Files // cancel the read and execution permissions of other group users

> Chmod g + rx, o + wx file // set the "read and execute" permission for users in the same group of files. Users in other groups have the "write and execute permissions"
> Chmod u-rwx, g-rw // cancel the permissions of a specific user

29. Number [absolute mode] Set File Permissions
Read, write, and executable
Binary Code indicates Computer Information
1-------------1
10-------------2
100-------------4

Example: Read: 1 Write: 2 execute 3
If the file permission is read/write, the number is 6.
If the file has only the read permission, the number is 1.
3. Do not know whether it is "read/write" or "execution permission". ambiguity arises.

The correct usage is: read 4 write 2 execute 1
1: Run
2: Write
3: Write and execute
4: Read
5. read and execute
6. Read and Write
7: read, write, and execute
> The chmod 777 file // The Master, users in the same group, and users in other groups have full permissions.
> The chmod 001 file // the master and the same group of users do not have the permission. Other groups of users have the executable permission.
Ppink.txt the master has the write and execution users in the same group have read users in other groups have read and executed
> Chmod 345 ppink.txt

30. Set permissions for directory Recursion
> The chmod 755 directory-R //-R parameter can be used to recursively Set permissions in the directory.

31. File Permission usage
-W-the file has only the write permission. [the original content cannot be viewed. The file can be written, overwritten, and forcibly saved.]
R -- the file has only the read permission. [You can view the original content, write it, Do not overwrite it, and forcibly save it.]
-- The x file has the executable permission. [You cannot see the original content. You can write, overwrite, and forcibly Save the content.]

32. directory permission
R -- the directory has the read permission. [You can read the files and cannot access them.]
-- The x Directory has the execution permission. [reading is not allowed, writing is not allowed, and access to the directory is allowed.]
-W-Directory: Some permissions [cannot be read, files cannot be added or removed, and files cannot be accessed]
Rw-you have read and write permissions. [You can read and cannot enter the Directory]
Rwx read, write, and executable: [You can read, reduce files, and access]
How to Write a directory: adding or removing files to a directory means writing

33. Operations on file permissions by users in the same group
R -- operation of read-only files [read, write, force save, the file owner and group have been changed]
-W-Write Permission [cannot be read. You can forcibly overwrite the write permission. The owner and group of the file are changed.]
-- Whether x can enter the Directory

[If a directory has executable permissions, you can switch to the Directory]

34. permissions on files or directories have no impact on super administrator root

35. Find the content we need in the specified file
> Grep Content File

36. View "Task Manager"
> Top

37. view memory information
> Free-m // The memory usage is displayed in MB.

38. view the file or directory size
> Du-h target // minimum unit limit (4 k) 1 byte

39. File Search
Find directory option value
> Find./-name abc.txt // find the file named abc.txt in the current directory
> Find/-name xxx // search for files in the root directory
> Find./-size // search by file size
Unit:
10 512 bytes default
100c 1 byte Unit
100 k 1024 bytes
> Find./-size + 100c // search for files larger than 100 bytes
> Find./-size-100c // search for files smaller than 100 bytes
> Find./-size 4 // search for files of 2048 bytes
> Find./-size 2 k // search for files with a size equal to 2048 bytes

> Find./-maxdepth 1 // find the file directory at Layer 2
> Find./-mindepth 1 // find the file at the shortest level.

> Find./-type f // find the file type through the type Query
> Find./-type d // find the directory type through type search

> Find./-user name // find the file whose owner is XX
> Find./-uid user ID // find the file whose owner number is XX
> Find./-nouser // search for files without a master
When a file is created, it is created by a user.
Some files are published to the network after they are created.
We downloaded the network files locally and put them in our own system.
The user who created this file is not in my own System
For example, the user ID for creating this file is 710 (username: runfa)

> Find./-perm permission 764 // search by File Permission

> Find./-name 'bao * '// perform a fuzzy search. The name prefix is the bao file.

40. Set 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. Prepare task scheduling commands
> Crontab-e // edit the task scheduling command
> Crontab-l // view the task scheduling command settings
Execute specific task commands
Minute Hour Date month week specific command
38 17 ***/home/shuhua/shanghai/newout. sh

0 represents Sunday

43. Set the system time
> Date-s "17:39:40 ";
> Date // view the system time

44. Set the file master
> Change owner
> Chown Master File

45. Set a group for the file
> Change group
> Chgrp group files

> Chown. group file

46. Set the owner and group for the file at the same time
> Chown master. group file
> Chown master. Group directory-R // recursively sets the master and group information for the directory. Both level-2 and level-3 directories are set.

 

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.