Common commands to use the French side:
1. CD:
CD dir: Switch the working directory to the DIR directory
CD: Switch to the user login directory
CD-: Switch to the top level directory (two directories switch to each other)
CD ~: Switch to home directory
CD ~username: Switch to the specified user home directory for root users only
2. PWD:
-l:shell problem correction occurs
-P: Print out a real physical directory (like a shortcut)
3, LS: in Linux all to. Files that begin with are hidden files
Option:-A displays all files, including hidden files
-a display except. .. Start with all files, including hidden files
-D does not display the contents of the directory, only displays the directory name (the directory becomes a non-directory file)
-L--long to display detailed property metadata for a file in a long format: properties ~
4, MkDir:
-p When creating a directory, if the parent directory does not exist, the parent directory is created first
-U Displays the execution of the command when the command is executed
5, RmDir: can only delete empty directory
-P If the parent directory is empty after the subdirectory is deleted, continue to delete
-V Displays the execution of the command when the command is executed
6. RM: Remove files and directories
-I interactive Delete with user
-F Force Delete without any representation
-R to remove the contents of a directory recursively
7, Touch: Timestamp, if the file does not exist, will create a new file
8, Stat: Display the detailed file content
Modify data content Change time metadata%a permissions
-C Display specific properties of a file in a specific format
9. Nano: Full Screen editing Tool
10. Cat:
-B numbering by row for non-empty line content
-N Numbering for all rows
-S: Merge multiple lines of empty rows into one row
-E: Show end of line terminator
11, reverse output of tac:cat
12. Head:
-n+ display the first few lines of the file, or abbreviated as "-#"
-c# display the first # Characters of a file
Displays the first 10 lines of the file if you do not add an option
13, Tail:
-N Displays the last few lines of the file, abbreviated to "-#"
-c# display the first # Characters of a file
-F always monitors changes at the end of the file, using CTRL + C to exit
14, 15, more less: page display of the contents of the file
More can't look back, less can look back
Date time-related commands:
16, hardware clocks: Hwclock clock
-S synchronizes the hardware clock to the system clock
-W synchronizes the system clock to the hardware clock
17. System Clock: Date
-S synchronizes the hardware clock to the system clock
-W synchronizes the system clock to the hardware clock
--set--date+ "Time" to set the hardware clock to times represented by
%f date in full format
%t time in full format
%y%m Month%d day%h%m minutes%s seconds
%s timestamp, number of seconds elapsed from 1970, 1, 1
19, Shutdown: Halt, Poweroff: Direct power reboot reboot
Shutdown
-H shut down the system
-R root re-boot
-K prompt to shut down, actually does not shut down the machine
-C cancels a shutdown job that is about to be performed
20. Logout: Log Out
Exit logout ^+d End Current Shell
21, CP: At least two parameters
-d copy of the meta if it is a symbolic link file, copy the symbolic link file directly to the target location instead of the linked file
-p preserves file permissions, ownership, and timestamp information when copying files
-r-r the ability to recursively replicate directories and files in a directory
-A is equivalent to the combination of-DPR options
Note: 1. There are at least two parameters
2, usually the last parameter is the target of this replication 1
3, if the single source replication, the target can not exist, can be a non-directory file
4. If the target of a multi-source replication must be a directory, and the file name cannot be changed during replication.
22. MV: Move, rename, grammar with CP
-F: Force overwrite files in the file destination location.
Vim is the abbreviation of VI improved and is an improved version of VI. In Linux, vi is considered to be the de facto standard editor because:
All versions of Linux have a VI editor;
Occupy less resources;
VI is more user-friendly than other editors such as Ed and ex.
You can use the VI editor to edit an existing file, create a new file, and open a text file in read-only mode.
Go to VI Editor
You can enter the VI editor in the following ways:
Command Description
VI filename opens if filename exists, otherwise a new file is created and then opened.
vi-r filename opens an existing file in read-only mode (view cannot be edited only).
View filename Opens an existing file in read-only mode.
For example, use the VI Editor to create a new file and open it:
$vi testfile
|
~
~
~
~
~
~
~
~
~
~
~
~
"Testfile" [New File]
Vertical bar (|) Represents the position of the cursor, and the tilde (~) indicates that the line does not have any content. If you don't have a ~, and you don't see anything, it means that the line must have a blank character (space, tab indent, line feed, and so on) or invisible characters.
Working mode
To learn more about VI before the first to understand the VI work mode, VI has three modes of operation:
1) Normal mode
When the shell enters the VI editor, it first enters normal mode. In normal mode, entering any character from the keyboard is interpreted as a command. There is no prompt in normal mode, executes immediately after the command is entered, does not require a carriage return, and the characters entered are not displayed on the screen.
In normal mode, you can execute commands, save files, move cursors, paste copies, and so on.
2) Edit mode
Edit mode is used primarily for text editing. Any characters entered by the user in this mode are saved as the contents of the file and displayed on the screen.
3) Command mode
Command mode, the user can perform some advanced processing of the file. Although commands in normal mode can do many things, it is necessary to perform some operations such as string lookups, substitutions, display line numbers, or command mode.
Note: There are several tutorials that say there are two modes of operation, which are merging command modes into normal mode.
Operating mode switching:
Enter edit mode when I (insert), C (modify), O (another line) command is entered in normal mode, and press ESC to return to normal mode.
Enter a colon in normal mode (:) can enter command mode. After entering the command press ENTER, the command will automatically return to normal mode after execution.
Tip: If you are not sure which mode you are currently in, pressing ESC two times will return to normal mode.
Exit VI Editor
Typically exits the VI Editor in command mode.
Exit Command description
Q If the file is not modified, it will be returned directly to the shell, otherwise prompt to save the file.
Q! forcibly exits without saving the modified content.
TheWq w command saves the file, and the Q command exits VI, which, together, saves and exits.
ZZ saves and exits, equivalent to Wq, but more convenient.
Before exiting, you can also specify a filename after the W command to save the file as a new file, for example:
W filename2
Save the current file as filename2.
Note: When you edit a file, the user's actions are based on the copy in the buffer. If you do not save to disk when you exit, the contents of the buffer will be lost.
Move cursor
To not affect the contents of the file, you must move the cursor under normal mode (press two ESC). Use the commands in the following table to move one character at a time:
Command Description
K Move cursor up (move one line)
J Move cursor down (move one line)
H Move the cursor to the left (move one character)
L Move the cursor to the right (move one character)
Two-point reminder:
VI is case-sensitive, and be careful not to lock uppercase when entering commands.
You can add a number to the front of the command as a prefix, for example, 2j moves the cursor down two lines.
Of course, there are many other commands to move the cursor, but remember, be sure to do it in normal mode (press two ESC).
Commands to move the cursor
Command Description
0 or | Position the cursor at the beginning of a line.
$ to position the cursor at the end of a line.
W navigates to the next word.
b navigates to the previous word.
( to the beginning of a sentence, the sentence is defined with a!.. three symbols.)
) to the end of a sentence.
{ move to the beginning of the paragraph.} &&&&&&
move to the end of the paragraph. &&&&&&&&&
[[ return to the beginning of the paragraph.] &&&&&&&&&&
]] to move forward to the beginning of the next paragraph. &&&&&&&&&&
n| move to nth column (current row).
1G moves to the first line of the file.
G moves to the last line of the file.
NG moves to the nth row of the file.
: N moves to the nth row of the file.
H move to the top of the screen.
NH moves to the position of the nth line at the top of the screen.
M moves to the middle of the screen.
L Move to the bottom of the screen.
NL moves to the position of the nth row at the bottom of the screen.
: xx is a number that represents a line that moves to the line number x.
Control commands
Some control commands can be combined with the Ctrl key, as follows:
Command Description
Ctrl+d rolling forward half screen
Ctrl+f scrolling forward full screen
Ctrl+u rolling back half screen
Ctrl+b Scroll backward through the entire screen
Ctrl+e scroll up one line
Ctrl+y scroll down one line
Ctrl+i Refresh Screen
Edit File
You can edit the file by switching to edit mode. There are a number of commands that can be switched from normal to edit mode, as shown below:
Command Description
I insert text before the current cursor position
I Insert text at the beginning of the current line
A inserts text after the current cursor position
A Inserts text at the end of the current line
o Create a row below the current position
O Create a row above the current position
Delete character
The following command allows you to delete a character or line from a file:
Command Description
X Delete the characters under the current cursor
X Delete the characters in front of the cursor
DW deletes characters from the current cursor to the end of a word
d^ Delete characters from the current cursor to the beginning of the line
d$ Delete characters from the current cursor to the end of the line
D Delete the character from the current cursor to the end of the line
DD Delete the line where the current cursor is located
You can add a number prefix to the command to indicate the number of repetitions, for example, 2x to delete the characters under the cursor twice, and 2DD to delete the row where the cursor was deleted twice in succession.
You are advised to practice the above commands and further study further.
Modify text
If you want to modify a character, word, or line, you can use the following command:
Command Description
CC Deletes the current line and enters edit mode.
CW Deletes the current word (word) and enters edit mode.
R replaces the character under the current cursor.
R replaces the character starting with the current cursor and presses the ESC key to exit.
S replaces the current character with the input character and enters edit mode.
S replaces the current line with the input text and enters edit mode.
Paste Copy
Copy-paste command in VI:
Command Description
yy copy when moving forward
Nyy copy n rows
YW copy a word (word)
NYW copy n rows
P Paste the copied text behind the cursor
P Paste copied text to the front of the cursor
Advanced Commands
Some of the following commands may seem odd, but will make your job more efficient, and if you're a VI heavy user, get to know it.
Command Description
J Connect the current row and the next row as a row
<< Move the current line one unit to the left (one indent width)
>> Move the current line one unit to the right (one indent width)
~ Change the case of the current character
^gctrl+g key combination to display the current file name and status
U undo changes made to the current line
U undo the last operation and press ' U ' again to restore the operation
: F Displays the position of the current cursor in the file, the file name, and the total number of rows in the file as percent sign (%)
: F filename renames the file to filename
: w filename save modified to filename
: E filename opens another file named filename
: cd dirname changes the current working directory to DirName
: E # switch between two open files
: N If you have opened multiple files with VI, you can use: N to switch to the next file
:p If you have multiple files open with VI, you can use: N to switch to the previous file
: N If you have opened multiple files with VI, you can use: N to switch to the previous file
: R file reads files and inserts them behind the current line
: NR file reads the file and inserts it behind the nth line
Text Lookup
If you want to do a full file search, you can enter/command in normal mode (press two ESC), then the status bar (the last line) appears "/" and prompts for the string to find, enter.
/command is to look down, and if you want to look up, can I use? Command.
At this point, the input n command can continue looking in the same direction, and the N command can continue in the opposite direction.
The searched string can contain characters with special meanings, and if you want to search for the characters themselves, you need to precede the backslash (\).
Partial list of special characters
Character description
^ matches the beginning of a line
. Match one character
* match 0 or more characters
$ matches the end of a line
[] matches a set of characters
If you want to search for a single character in a row, you can use the F or F command, F to search up, F to search down, and position the cursor to match the character.
You can also use the T or T command: the t command to search up and position the cursor in front of the matching character; the T command searches down and positions the cursor behind the matching character.
Set command
The SET command provides some settings for the VI editor. Use the SET command to enter command mode.
: Set command options
Command Description
: The Set IC search ignores case.
: Set AI sets auto indent (Auto align).
: Set Noai cancels auto indent (auto-alignment).
: Set nu displays line numbers.
: Set SW sets the number of spaces to indent, for example, to set the number of indent spaces to 4::set sw=4.
: Set WS -loop Search: If the specified character is not found until the end of the file, it will go back to the beginning to continue looking.
: Set WM sets the word wrap, for example, to set a line break when 2 characters from the margin:: Set wm=2.
: Set RO changes the file type to read-only.
: Set term output terminal type.
: Set BF ignores input control characters such as BEL (Bell), BS (BACKSPACE), CR (carriage return), etc.
Run command
Switch to command mode, and then enter! command to run the Linux command.
For example, before you save a file, if you want to see if the file exists, enter
:! Ls
You can list the files in the current directory.
Press any key to return to the VI editor.
Text substitution
Switch to command mode, and then enter the s/command to replace the text. The syntax is:
: s/search/replace/g
Search is the retrieved text, replace is the text to be replaced, and G represents the global substitution.
Enter a colon (:) Enter command mode and press ESC two times to enter normal mode.
The meaning of the case of the command is not the same.
You must be in edit mode to enter content.
Linux command 1~23