In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "CentOS file viewing and editing example analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "CentOS file view and editing example analysis" this article.
2.1 introduction to the cat command
The original meaning of the cat command is concatenate, which is used to connect multiple file contents and output them to the standard output stream (the standard output stream defaults to the screen). In the process of practical application, we often use it to display the contents of the file. If you are familiar with the type command under MS-DOS, it is not difficult to master the cat command. Common examples of this command are as follows:
1 cat file1.txt displays the contents of the file1.txt file
two
3 cat file1.txt file2.txt displays the contents of file1.txt and file2.txt files
four
5 cat-n file1.txt displays the contents of the file1.txt file as well as the line number
2.2 introduction to the vi command
Vi is the abbreviation of "Visual Interface", and its position on Linux is just like that of Edit program on DOS. It can perform many text operations, such as output, delete, find, replace, block operation, and so on, and users can customize it according to their own needs, which other editing programs do not have.
Vi is not a typesetting program, it is not like Word or WPS can be arranged for fonts, formatting, paragraphs and other attributes, it is just a text editor.
Vi has no menus, only commands, and there are many commands. Limited to space, this article only introduces the commonly used commands.
Vi has three basic working modes: command line mode, text input mode, and last line mode.
Command line mode:
At any time, no matter what mode the user is in, just press the "ESC" key to put vi into command-line mode, and when you enter the vi command to start the vi editor in the shell environment, you are also in this mode.
In this mode, users can enter a variety of legitimate vi commands to manage their own documents. At this point, any character entered from the keyboard is interpreted as an editing command, and if the character entered is a legitimate vi command, vi completes the corresponding action after accepting the user's command (but it is important to note that the entered command is not displayed on the screen). If the character entered is not a legitimate command of vi, vi will ring the alarm.
Text input mode:
Enter insert command I, add command a, open command o, modify command c, replace command r, or replace command s in command mode to enter text input mode. In this mode, any characters entered by the user are saved by vi as the contents of the file and displayed on the screen. During text entry, if you want to return to command mode, press the "ESC" key.
Last line mode:
In command mode, the user presses the ":" key to enter the last line mode, where Vi displays a ":" as a prompt for the last line of the display window (usually the last line of the screen), waiting for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the edit buffer to a file). After the last line command is executed, vi automatically returns to command mode.
If you change your mind while entering a command in the last line mode, press the "ESC" key or use the Backspace key to delete all the commands entered, and then press the Backspace key to make vi return to the command mode.
2.2.1 entry and exit of vi
In shell mode, type vi and the file name you need to edit to enter vi. For example:
1 vi example.txt
You can edit the example.txt file. If the file exists, the contents of the file are displayed in the editing interface and the cursor is positioned on the first line of the file; if the file does not exist, there is nothing in the editing interface. If you need to place the cursor on the nth line of the file after entering the vi editing interface, add the "+ n" parameter after the vi command. For example, if you want to start at line 5 of the example.txt file, use the following command:
1 vi + 5 example.txt
When you exit vi, you need to enter the exit command "Q" in the last line mode. If you are in text input mode, first press "ESC" to enter command mode, and then enter ":" to enter the last line mode. In the last line mode, you can use the following exit command
1: Q exit directly. If the content of the document is modified in text input mode, you cannot exit.
two
3: wq exits after saving.
4: X equals "wq".
five
6: Q!-do not save the content, force exit.
2.2.2 display the line number in vi
In the last line mode, enter the following command.
1 set number
Enables vi to display line numbers in the editing interface.
In addition, in the last line mode, you can use the following "nu" command (shorthand for number) to display the line number of the cursor and the contents of the line.
2.2.3 cursor movement operation
Cursor movement is undoubtedly the most frequently used operation in a full-screen text editor. Only by skillfully using these commands that move the cursor can the user quickly and accurately reach the desired location for editing.
Cursor movement in vi can be in either command mode or text input mode, but in different ways.
In text input mode, you can use the four arrow keys on the keyboard to move the cursor directly; in command mode, there are many ways to move the cursor. You can not only use the four arrow keys to move the cursor, but also use the four keys h, j, k, l instead of the four direction keys to move the cursor, which can avoid the contradictions caused by different keyboard definitions on different machines. and after using proficiency, you can complete all operations without leaving the position of the letter keyboard, so as to improve work efficiency.
The following commands complete cursor movement in command line mode:
The h cursor moves to the left, and if you enter the number n before pressing the h command, the cursor moves n characters to the left
The cursor moves to the right, and if you enter the number n before pressing the l command, the cursor moves right by n characters
Move the j cursor up, if you enter the number n before pressing the j command, the cursor moves up n characters
The k cursor moves down, and if you enter the number n before pressing the k command, the cursor xia moves n characters
0 (zero) move the cursor to the beginning of the line
Move the cursor to the end of the line
The H cursor moves to the first line displayed on the screen (not necessarily a file header)
The L cursor moves to the last line displayed on the screen (not necessarily the end of the file)
Move the M cursor to the middle line of the screen
Move the nG cursor to line n
W or W move the cursor right to the beginning of the next word
E or E if the cursor start position is within the word (that is, not at the end of the word), the command moves the cursor to the end of the word; if the cursor start position is at the end of the word, the command moves the cursor to the end of the next word.
B or B if the cursor is within the word (that is, not the beginning of the word), the command moves the cursor to the beginning of the word; if the cursor is at the beginning of the word, the command moves the cursor to the beginning of the previous word
The Ctrl+G status command displays the status of the current editing document. Includes the file name being edited, whether it has been modified, the current line number, the number of lines in the file, and the percentage of lines before the cursor in the entire file.
In addition, you can also move the cursor throughout the file through the following commands in last-line mode:
Move the cursor to the nth line of the file
Move the cursor to the last line of the file
2.2.4 text insertion operation
In command mode, any character entered by the user is interpreted and executed by vi as a command. If the user wants to treat the input character as text content, he should first switch the working mode of vi from command mode to text input mode. The way to switch is to use the following command:
1. Insert (Insert) command
Vi provides two insert commands: I and I.
(1). The I command inserts the text in front of the cursor, and you can use the key to delete the wrong input during the insertion process. At this point, the vi is inserted, and the bottom line of the screen displays the word "- INSERT-".
(2). I command this command moves the cursor to the beginning of the current line and then inserts text before it.
two。 Additional (append) command
Vi provides two additional insert commands: an and A.
(1). A command this command is used to append new text after the current position of the cursor, the newly entered text is placed after the cursor, the original text behind the cursor will move backward accordingly, and the cursor can be anywhere on a line.
(2). The A command differs from the a command in that the A command moves the cursor to the end of the line, where the new text is inserted, and when the A command is entered, the cursor automatically moves to the end of the line.
The an and A commands are the only way to insert text at the end of a line.
3. Open the open command
Whether it's the Insert command or the append command, the insertion starts somewhere on the current line. If we want to insert some new rows before or after a row, we should use the open command.
Vi provides two open commands: O and O.
(1). O command this command will open a new line below the line of the cursor and place the cursor at the beginning of the line, waiting for text to be entered. Note that when using delete characters, only characters after the position starting from the insertion mode can be deleted, not for previous characters.
(2). The O command, in contrast to the o command, inserts a line above the line of the cursor and places the cursor at the beginning of the line, waiting for text to be entered.
2.2.5 text modification operation
In command mode, you can use a variety of relevant commands provided by vi to modify the text, including deleting, copying, replacing and replacing the text content.
1. Text deletion / move
When editing text, we often need to delete some unwanted text, we can use the key to delete the wrong or unneeded text, but there is a limitation that when deleted to the header, it is impossible to delete the content of the line above.
In command mode, vi provides a number of delete commands. Most of them start with d. The commonly used ones are:
(1). Delete a single character
X deletes the character at the cursor. If you add a number n before x, delete the n characters to the right from the position of the cursor.
X deletes the character in front of the cursor, and if you add a number n before X, delete the n characters that start to the left from the character in front of the cursor.
Obviously, these two commands are quick ways to delete a small number of characters.
(2). Delete multiple characters
Dd deletes the entire line where the cursor is located. You can add the number n before dd to indicate that the contents of the current line and subsequent nmur1 lines can be deleted.
Both D and d$ commands have the same function, deleting content from the beginning of the cursor to the end of the line.
D0 removes content that starts one character in front of the cursor to the beginning of the line.
Dw deletes a word. If the cursor is in the middle of a word, delete it to the end of the word from the position of the cursor. As with the dd command, you can add the number n before dw. Means to delete n specified words.
If the user accidentally deletes by mistake, never mind vi, the command to restore the misoperation is provided, and the recovered content can be moved and placed anywhere in the text. The restore command uses "np", where n is the number of times you need to restore. For example, if you delete a line using the dd command, and then use the "2p" command, the deleted content will be reinserted twice.
Through the combined use of dd command and p command, it is very convenient to realize the moving operation of text lines.
two。 Text copy command
Yy copies the entire line where the cursor is located. The number n can be added before the yy to indicate that the contents of the current line and the subsequent nmur1 line are copied.
After the text line is copied, you can paste the text line anywhere by using the "p" command described above.
The functions of dd, yy and p commands in vi are similar to the "cut", "copy" and "paste" commands of graphic editors in Windows.
3. Cancel the previous command (Undo)
Canceling the previous command (Undo), also known as the undo command, is a very useful command that cancels the impact of the previous misoperation or inappropriate operation on the file and returns it to the state it was before the misoperation or inappropriate operation was performed.
There are two forms of canceling the previous command, typing the characters u and U in command mode. Their function is to cancel the command you just entered and return to the original situation. The difference between lowercase u and uppercase U is that the function of the uppercase U command is to revert to the situation before the misoperation of the command, that is, if you use the U command after inserting the command, delete what has just been inserted; if you delete the command and use the U command, it is tantamount to inserting what has just been deleted at the cursor. Here, all commands that modify the text are regarded as insert commands, that is, the U command can only cancel the previous operation, if you undo the previous operation with the U command, when you press the U key again, it is not to undo the operation of the previous step, but to undo the operation performed by the U command, that is, to return to the state before the first use of the U command, and the result is to do nothing. The lowercase u command restores the current line to the state it was before it was edited, no matter how many times it has been edited.
4. Repeat command (Redo)
Repeating commands is also a very common command. In text editing, you often encounter the need to repeat some operations mechanically, and then you need to use repetitive commands. It allows the user to easily execute a complex command that has just been completed earlier.
Repeat commands can only work in command mode, where you press "." The key is fine. When you execute a repeated command, the result depends on the current position of the cursor.
2.2.6 text search and replace operation
When editing text, you may need to search for or locate a specific word or part of a word. The vi editor has the ability to search forward or backward for a specified pattern.
"/" is the pattern search command of the vi editor. After typing "/", a line appears at the bottom of the screen, and a diagonal shoulder appears at the beginning of the bottom line, and the cursor is placed after the oblique shoulder. At this point, you can type the pattern you want to search at the cursor position. After typing is complete and the ENTER key is pressed, the editor will begin to search the end of the file for the pattern you typed from the location of the cursor. If the entered pattern is found, the cursor will rest on the found mode. After finding a matching pattern, if you still need to search for the next matching pattern, use the command "n"; if you need to find the last matching pattern, use the "N" command.
Besides, "?" The command is also a pattern search command. The difference between "/" and "/" is / from the cursor when
The front location searches the end of the file, and "?" The command searches the file header by the current location of the cursor.
The text replacement operation requires the use of the last line mode, that is, all text replacement operation commands begin with ":".
The format of the text replacement command is:
: s/text1/text2 is used to replace the first "text1" searched in the paragraph with the cursor with "text2"
: s/text1/text2/g is used to replace all "text1" with "text2" in the paragraph where the cursor is located.
: mminute nstext _ text1 _ text _ 2max is used to replace all searched "text" from the m line to the end of the n line with text2. You can use $to denote the last line, that is, "1J $" to replace all eligible characters in the document.
The above is all the contents of the article "sample Analysis of CentOS File viewing and Editing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.