Practical explanation of editing files, saving and exiting in linux

Practical explanation of editing files, saving and exiting in linux

How to save and exit after editing a file in Linux?

The command is wq to save and exit.

First press ESC to enter Command mode, then enter ": wq " and press Enter to save and exit.

There are different options for vi to save files, corresponding to different commands. You can choose the one you need from the following commands:

1. wq saves the file and exits vi

2. w saves the file but does not exit vi

3. w file saves the changes to another file without exiting vi

4. q does not save the file and exits vi

Finally, press Enter.

Additional information

Exit Vi When you have finished editing the file and are ready to exit Vi and return to the shell, you can use one of the following methods: Press the capital letter Z twice in command mode. If the currently edited file has been modified, Vi saves the file and exits to return to the shell.

If the currently edited file has not been modified, Vi exits directly and returns to the shell. In the last line mode, enter the command: w Vi saves the currently edited file but does not exit. Instead, it continues to wait for the user to enter commands. When using the w command, you can give the edited file a new file name.

Linux is a free to use and free to spread Unix-like operating system. It is a multi-user, multi-tasking operating system based on POSIX and UNIX that supports multi-threading and multi-CPU. It can run major UNIX tools, applications, and network protocols. It supports both 32-bit and 64-bit hardware. Linux inherits the network-centric design concept of Unix and is a multi-user network operating system with stable performance.

Strictly speaking, the word Linux itself only refers to the Linux kernel, but in fact people have become accustomed to using Linux to describe the entire operating system that is based on the Linux kernel and uses various tools and databases of the GNU project.

Additional content:

For example, if you want to add the content "I am a boy" to the test.txt file, test.txt is in the current directory.

Method 1: vi editing method

Open the terminal, enter vi test.txt and press Enter. Press a or i to enter the editing mode, enter I am a boy, and then press the Esc key to exit the editing mode. Enter :wq to save and exit.

Method 2: echo command method

Open the terminal and enter

echo 'I am a boy' >> ./test.txt

Note: Append single line text method

Method 3: cat command method

cat >> ./test.txt <<EOF

I am a boy

EOF

Note: The ending EOF must be aligned to the beginning of the letter, appear in pairs, and can be replaced by other characters.

Method 4: cat editing method

cat >> ./test.txt (press Enter to start editing the input content)

I am a boy.

Press cntl+d to end editing.

This is the end of this article about the practical explanation of how to save and exit after editing files in Linux. For more information about how to save and exit after editing files in Linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to the problem of E514: write error (file system full?) when saving files in Linux using vim

<<:  Win32 MySQL 5.7.27 installation and configuration method graphic tutorial

>>:  jQuery implements the bouncing ball game

Recommend

Vue implements the question answering function

1. Request answer interface 2. Determine whether ...

Solution to the conflict between Linux kernel and SVN versions

Phenomenon The system could compile the Linux sys...

Draw a heart with CSS3

Achieve resultsRequirements/Functionality: How to...

JavaScript Basics Objects

Table of contents 1. Object 1.1 What is an object...

Vue application example code based on axios request encapsulation

Table of contents What is axios? Axios request ty...

Steps to split and compress CSS with webpack and import it with link

Let's take a look at the code file structure ...

How to avoid the trap of URL time zone in MySQL

Preface Recently, when using MySQL 6.0.x or highe...

Notes on the MySQL database backup process

Today I looked at some things related to data bac...

Solution to Docker's failure to release ports

Today I encountered a very strange situation. Aft...

5 things to note when writing React components using hooks

Table of contents 01. Use useState when render is...

MySQL latest version 8.0.17 decompression version installation tutorial

Personally, I think the decompressed version is e...

Swiper.js plugin makes it super easy to implement carousel images

Swiper is a sliding special effects plug-in built...

Several ways to easily traverse object properties in JS

Table of contents 1. Self-enumerable properties 2...

Docker automated build Automated Build implementation process diagram

Automated build means using Docker Hub to connect...