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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article editor for you a detailed introduction of "Linux mv command how to use", the content is detailed, the steps are clear, the details are handled properly, I hope this "Linux mv command how to use" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.
The mv command is an abbreviation for move, which can be used to move files or rename files (move (rename) files). It is a commonly used command on Linux systems and is often used to back up files or directories.
1. Move Fil
It is important to note that the source and destination addresses of the file must be different when moving the file. Here is an example. If you want to move the file_1.txt file from the current directory to another directory, take / home/pungki/ as an example, the syntax should be as follows:
$mv file_1.txt / home/pungki/office
As we can see, when we move the file_1.txt file, the file_1.txt of the previous directory is deleted.
two。 Move multiple files
If you want to move more than one file at a time, we can put them on one line and separate them with spaces.
$mv file_2.txt file_3.txt file_4.txt / home/pungki/office
If your files have rules to follow, then you can use wildcards. For example, to remove all files with the .txt extension, we can use the following command:
Mv * .txt / home/pungki/office3. Move directory
Unlike the copy command, moving directories with the mv command is quite straightforward. You can use the mv command without options to move the directory. You can see it at a glance by looking at the screenshot below.
4. Rename a file or directory
We also use the mv command to rename files or directories. However, the destination location and source location must be the same. Then the file name must be different.
Suppose our current directory is / home/pungki/Documents, and we want to rename file_1.txt to file_2.txt. Then the command should be as follows:
$mv file_1.txt file_2.txt
If it is an absolute path, it should look like this:
$mv / home/pungki/Documents/file_1.txt / home/pungki/Documents/file_2.txt5. Rename directory
The rules in the previous paragraph also apply to directories. Look at this example:
$mv directory_1/ directory_2/6. Print mobile information
When you move or rename a large number of files or directories, you may want to know if your command has been successfully executed without going to the target location to check. The-v option is about to be used.
$mv-v * .txt / home/pungki/office
This method is also applicable to directories.
7. Use interactive mode
When you move the file to another location and that location happens to have the same file, the mv command will overwrite the original file. There are generally no hints about this behavior of mv. If you want to generate a prompt about overwriting the file, we can use the-I option. (note: usually distributions use-I as the default option through the alias command, so there is a prompt. )
Suppose we want to move file_1.txt to / home/pungki/office. Meanwhile, there is already a file_1.txt file in the / home/pungki/office directory.
$mv-I file_1.txt / home/pungki/office
This prompt will let us know the existence of file_1.txt at the target location. If we press the y key, then that file will be deleted, otherwise it won't.
8. Use update option
The-I option prompts us about overwriting files, while-u performs updates only when the source file is newer than the destination file. Let's take a look at the following example:
If file_1.txt and file_2.txt have the following characteristics:
File_1.txt has 84 bytes file size and it last modified time is 12:00File_2.txt has 0 bytes file size and it last modified time is 11:59
We want to move them to the / home/pungki/office directory. But the destination address already has file_1.txt and file_2.txt.
We move file_1.txt and file_2.txt from the current directory to / home/pungki/office with the following command
$mv-uv * .txt / home/pungki/office
You can see that these files have been moved. These files can be moved because their recently modified timestamps are newer than the files in the / home/pungki/office directory.
9. Do not overwrite any existing files
If the-I option asks us if we want to overwrite the file, then the-n option will not allow us to overwrite any existing files.
Continuing with the example in point 8, if we replace-u with-n and add the-v option, we will see that no files have been moved to the / home/pungki/office directory.
Mv-vn * .txt / home/pungki/office10. Create a backup on replication
By default, moving a file will overwrite the existing target file. But what if we move the wrong file and the target file has been overwritten by the new file? Is there a way to recover previous files? The answer is yes. We can use the-b option. This option backs up the old file when the new file overwrites the old file. Here we also take point 8 as an example.
$mv-bv * .txt / home/pungki/office
As you can see in the screenshot, files named file_1.txt~ and file_2.txt~ appear in the / home/pungki/office directory. The tilde (~) means that these files are backup files. As we can see from their properties, these files are older than file_1.txt and file_2.txt.
11. Unconditionally overwrite existing files
(translation note: this section is supplemented by the translator, and this important option is omitted from the original text.)
You can use the-f option when you want to overwrite existing files or directories anyway. If you specify both the-f option and the-I or-n option, the-f option overrides them-that is, without any prompt, so know what you are doing when using this parameter.
$mv-f * .txt / home/pungki/office read here, this article "how to use the mv command of Linux" has been introduced. If you want to grasp the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, 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.