In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to understand mv and rm commands. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Introduction to 01 command
We have already talked about the creation and replication of files and directories. Today we will talk about cutting and deleting.
Mv-- moves, renames files
Rm-- deletes a file
02 order detailed explanation
Grammar
Mv [option] Parameter 1 Parameter 2rm [option] Parameter
Abbreviation of mv,move, move; abbreviation of rm,remove, delete. With this introduction, I believe it is easier for alumni to understand and remember the use of commands.
Parameters.
Mv [options] Source File destination File
In syntax, the mv command and the cp command are actually very similar. Options and parameters are similar, and there are three modes.
The difference is that the cp command copies a file in another place, and the whole computer has two files with the same content, while the mv command moves the file to another place, or there is only one such file on the whole computer.
Note that executing the mv command on a file does not update the time attribute of the file.
However, executing the cp command updates the time attribute of the file by default.
Except for the name, the content and time attributes are the same, so the mv command is also used to rename the file.
The arguments to the rm command can be files, directories, or both files and directories, separated by spaces.
Option
The options of the mv command are similar to those of the cp command, with "- I" interaction, "- n" not overwriting, "- f" forcing, and "- u" updating, which are not discussed here. Let's talk about a "- b" backup option, which is also available with the cp command.
First, let's create an empty file.
Then move 1.txt to 2.txt in the same directory. Since 2.txt already exists, the original content of 2.txt will be overwritten by default. At this point, we add the "- b" option, and the system will generate a backup file of 2.txt before overwriting.
As you can see, there is an extra 2.txt ~ file in the directory, which is the backup of the original 2.txt file, so there is no content to check it with the cat command.
In addition, introduce a "- t" option, which is used to specify the target directory to be moved, and then move all files after the target directory to the target directory.
Specify that the target directory is the test directory, and then move all the test directory followed by 1, 2, and 3 to it.
Of course, you can do this without using the "- t" option and using the default syntax. However, using the "- t" option to specify the target directory, to a certain extent, it is convenient for everyone to quickly understand the meaning of the command. In the specific work, alumni can use it according to their own habits.
You may not listen to mv orders very often, but I'm sure you've heard rm orders more than once or twice. What input error command downtime, what from deletion to running away, basically related to the rm command.
Sharp-eyed alumni may notice that when I talk about parameters, I use the rm command to delete files, not directories, because the rm command does not delete directories by default.
As you can see, the system explicitly indicates that it cannot be deleted because test is a directory. If you want to delete a directory, you must add the "- r" option.
But the mv command operates on directories and does not require the "- r" option.
Without adding the "- r" option, the mv command still moves the test directory to the Desktop directory.
Linux has a large number of commands, with different commands and options. It is normal that people may be confused or easy to forget when they first come into contact, and they will become more and more proficient if they knock a few more times.
The "- r" option is frequently used by the rm command, and another option that is frequently used is the "- f" option.
As you can see, after using the "- f" option, the system deletes the specified files and directories without any prompt, which is why the "rm-rf" command often goes wrong.
Finally, I would like to remind you that executing the rm command is not prompted by default. I am prompted here because I set the "- I" option to execute the rm command.
This is called an alias, and executing the rm command is actually executing "rm-I". So some alumni in the implementation of the rm command, the system without prompting to delete the file directly, encounter this situation do not need to panic, set it. In addition, for security reasons, it is also recommended to set prompts.
03 knowledge summary
Syntax: mv [option] Parameter 1 Parameter 2 rm [option] Parameter usage: mv-- Mobile, Rename file rm-- delete file options: mv:-i-- interaction-nmure-do not overwrite-umure-update-fmurf-force-bmurf-backup-tmure-specify target directory rm:-r, -Rmure-delete directory-fmurf-force-dmure-delete empty directory other: alias-- aliases on how to understand mv, rm commands are shared here I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.