In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the mv command under Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Mv is also the next very frequently used command for Linux, but what other advanced uses do you know besides some basic usage?
1. Basic usage
Move one / more files
Move one or more directories
Rename the file / directory.
These are very basic uses, and there is no need to repeat them. Here are some more advanced uses.
two。 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'? Y
4. 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' # destination does not have a file3.txt file So successfully move [alvin@VM_0_16_centos mv_test] $ls des file2.txt
5. Use 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 newer 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] $ls des file2.txt
6. 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-rw-rw-r-- 1 alvin alvin 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.
Thank you for reading this article carefully. I hope the article "how to use mv commands under Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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
Upload script: echo * * > > db_bak_logs.txtdate / t > > db_b
© 2024 shulou.com SLNews company. All rights reserved.