Beginner [Linux] basic commands "touch, cat, more, cp, rm, vm"

Table of contents

1. touch

2. cat

Three, more

4. cp

Five, rm

6. mv


1. touch

1. Function: Used to create files

2. Syntax: touch [Linux] path

                (1), touch has no options, the parameter is required , indicating the file to be created , both absolute path and relative path are acceptable.

3. Practical demonstration

Practical demonstration:

 It can be seen that the user in the home directory did not have the test4 file at the beginning. When we used the touch test4 command (using a relative path), a test4 file was created in the current working directory. There is still a big difference between files and folders. You can see that the fonts of files are white , while the fonts of folders are blue .

When we enter the ls -l command:

The difference is even more obvious. Our folders start with the " d " prefix, while the files start with the " - " prefix.


2. cat 

1. Function: View the contents of the file

2. Syntax: cat [Linux] path

                There are no options, only parameters , that is, the file to be viewed, either absolute path or relative path.

3. Practical demonstration

Practical demonstration:

We first find the test4 file we just created in the Linux graphical interface, and edit a piece of text on the graphical page.

 After creating it, try using the cat test4 command, and then you can view the contents of the test4 file very well .

 


Three, more

1. Function: Used to view the contents of the file. Compared with cat, more supports page turning ( "space" to turn pages, "q" to stop page turning and exit the more command ), while cat displays the entire file at once. content

2. Syntax: more [Linux] path

                (1) There are no options, only parameters , that is, the content to be displayed, both absolute paths and relative paths are available.

                (2) Support page turning, which can be displayed page by page

3. Practical demonstration

After we enter the more /etc/services command, we can see that the services file is not displayed all at once, and there is an additional word more (0%).

When we press "Space " several times in a row : we find that it becomes More-(%1) . If we keep pressing Space, we will continue to page down. Until the page is finished.

 

 When we try to press "q" : we find that we will exit the view


4. cp command (English name: copy)

1. Function: Used to copy files or folders

2. Syntax: cp [-r] Parameter 1 Parameter 2

                (1) -r option, optional, used to copy folders , indicating recursion

                (2) Parameter 1, the file or folder to be copied

                (3) Parameter 2, the file or folder to be copied . If the target does not exist , a target file will be created to ensure that the target file exists.

3. Practical operation

Practical operations:

We first create a test5 file in the current working directory

 We have already put a piece of content in the test4 file before, but test5 has no content.

When we enter cp test4 test5 :

 We can see that the content of test4 is copied to test5 very well.

And if we want to copy the folder, we need to bring the "-r" option.

You can see that there are test1 folder and test3 folder in our current working directory.

 The contents of the test1 folder and the test3 folder are as follows:

 

Enter cp -r test1 test3 , we copy the test1 folder to the test3 file 

Combined with the graphical interface, you can easily see that the test1 folder is copied to the test3 folder.


5. mv (English name: move)

1. Function: Used to move files or folders

2. Syntax: mv parameter 1 parameter 2

             (1) Parameter 1: File or folder to be moved

             (2) Parameter 2: The file or folder to be moved to . If the target does not exist, rename it to ensure that the target exists.

3. Practical demonstration

Practical demonstration:

As you can see, our current working directory contains files test5 and tset5

The contents in test4 and test5 are respectively:

 When we enter mv test4 test5 , the test4 file is moved to the test5 file (actually very similar to the Windows cut function) as shown in the figure

 We can see that the content on test4 is gone, but the content of the previous test4 appears on test5, and the same is true for the folder.

When the target folder does not exist , a target file will be created , as shown in the figure, still in our working path.

We move the test1 folder to the test folder. Because there is no test folder in the working directory, a test folder will be generated , but the test1 folder will no longer exist. The generated test folder will be the same as the test1 folder. The content is the same , as shown in the picture


6. rm (English name: remove)

1. Function: Can be used to delete files or folders.

2. Syntax: rm [-r -f] Parameter 1 Parameter 2...Parameter n

                (1) -r option, used to delete folders, the same as the cp command

                (2) -f option, forced deletion (no confirmation message will be prompted),

                        Ordinary users will not be prompted for information when using commands. Only root administrator users will be prompted for deletion information.

                        Therefore, ordinary users do not need the -f option .

                (3) Parameter 1 Parameter 2...Parameter n represents the file or file path to be deleted, separated by spaces

3. Practical demonstration:

Practical demonstration:

When we enter rm tset5 , we will find that the tset5 file has been deleted.

When we enter rm -r test , we will find that the test file has been deleted.

Supplement: The rm command is used for wildcard characters

 To use the -f option, we need to switch to the administrator user , enter su - root , and then enter the password you set , you will enter the administrator user. When we want to exit the administrator user, we can enter the exit command to exit, as shown in the figure :

(Note: Remember to log out if you are a temporary administrator)

 The original ordinary user identifier "#" will also be changed to the administrator user identifier "*"

When we want to delete a file or folder, he will prompt us whether to delete it, y means delete , n means cancel.

And when we don’t want him to jump out of the prompt box, we can use the -f option, which means not to prompt and delete it directly , as shown in the figure

 If you are temporarily using up the administrator user, remember to exit, because the administrator user has great rights. If you delete important files or folders, the virtual machine may be damaged, and you will need to reinstall the virtual machine at that time (for example, rm -rf / command), it is more dangerous after work. If you delete the size randomly, you may get into trouble.

 Therefore, the rm command is actually a dangerous command and should be used with caution.

Guess you like

Origin blog.csdn.net/cool_tao6/article/details/130840170
Recommended