In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the special uses of mv commands in Linux". In daily operation, I believe that many people have doubts about the special use of mv commands in Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the special use of mv commands in Linux?" Next, please follow the editor to study!
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. Basic usage
1. Move one or more files
2. Move one or more directories
3. Rename the file / directory.
These are very basic uses, and there is no need to repeat them. Here are some more advanced uses.
2. Print operation information
If we only move one or two or a few files / directories, we can also go to the target location to see if the file has been moved successfully. But what if there are thousands of documents? How do you know if our operation has been successful without going to the target location to check it? We can add the-v option.
[alvin@VM_0_16_centos mv_test] $mv-v * .txt / home/alvin/test/mv_test/des/'file1.txt'->'/ home/alvin/test/mv_test/des/file1.txt''file2.txt'->'/ home/alvin/test/mv_test/des/file2.txt''file3.txt'->'/ home/alvin/test/mv_test/des/file3.txt''file4.txt'-> '/ home/alvin/test/mv_test/des/file4.txt''file5.txt'->' / home/alvin/test/mv_test/des/file5.txt'
Of course, this method also applies to moving directories.
3. Use interactive mode
By default, we don't get any prompts when we move files / directories. If we have a file / directory with the same name at the target location, the mv command will not prompt and directly replace the original file. Such an operation can sometimes have disastrous consequences.
In this case, we can add a-I option, which will prompt when the target location has a file with the same name. If you confirm that you want to overwrite the target file, type y.
[alvin@VM_0_16_centos mv_test] $mv-I file1.txt / home/alvin/test/mv_test/des/mv: overwrite'/ home/alvin/test/mv_test/des/file1.txt'? Y4. Do not overwrite files with the same name
If there is a file with the same name in the target location, we do not want it to be overwritten, we can add the-n option.
[alvin@VM_0_16_centos mv_test] $ll * .txt des/*.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:26 file2.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:35 file3.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:26 des/file1.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:27 des/ file2.txt [Alvin @ VM_0_16_centos mv_ Test] $mv-nv * .txt / home/alvin/test/mv_test/des/'file3.txt'->'/ home/alvin/test/mv_test/des/file3.txt' # there is no file3.txt file in the target location So successfully move [alvin@VM_0_16_centos mv_test] $lsdes file2.txt5 and use the update option
When there is a file / directory with the same name in the target location, we only want the source file to be updated than the target file timestamp, otherwise it will not be executed. In this case, we can use the-u option.
[alvin@VM_0_16_centos mv_test] $ll * .txt des/*.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:26 file1.txt # source file timestamp is updated than destination file timestamp-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:26 file2.txt # source file is older than destination file timestamp-rw-rw-r-- 1 alvin alvin 0 Feb 8 16:53 des/file1.txt-rw -rw-r-- 1 alvin alvin 0 Feb 8 17:27 des/ file2.txt [Alvin @ VM_0_16_centos mv_test] $mv-uv * .txt / home/alvin/test/mv_test/des/'file1.txt'->'/ home/alvin/test/mv_test/des/file1.txt' # only timestamped updated files are replaced [alvin@VM_0_16_centos mv_test] $lsdes file2.txt6, Create a backup before overwriting
The target location already has a file with the same name, so if you overwrite it directly, it always feels a bit unreliable, what if the decision is wrong now? Is it possible to back up the target file before overwriting it? The answer is yes, just add a-b option.
[alvin@VM_0_16_centos mv_test] $mv-bv * .txt / home/alvin/test/mv_test/des/'file1.txt'->'/ home/alvin/test/mv_test/des/file1.txt' (backup:'/ home/alvin/test/mv_test/des/file1.txt~') 'file2.txt'->' / home/alvin/test/mv_test/des/file2.txt' (backup:'/ home/alvin) / test/mv_test/des/file2.txt~') [alvin@VM_0_16_centos mv_test] $ll des/total 0 Feb 8 17:41 file1.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:26 file1.txt~-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:26 file2.txt-rw-rw-r-- 1 alvin alvin 0 Feb 8 17:27 file2.txt~-rw-rw-r -- 1 alvin alvin 0 Feb 8 17:35 file3.txt
You can see that before overwriting, the target file will be backed up as a file with a tilde, and careful readers will notice that the timestamp of the overwritten file is not the same as that of the backup file.
At this point, the study on "what is the special use of the mv command in Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.