大网数据广告活动
服务器运维问答

Is mv with wildcard still atomic

· 52CE 我爱测

My understanding is that mv dir1/file1 dir2/ is atomic, Is mv dir1/* dir2/ also atomic? As an example, assume there are 10 files in dir1 that are 10GB each.

问题原文

原帖链接 · MR2Power · CC BY-SA 4.0

My understanding is that mv dir1/file1 dir2/ is atomic,

Is mv dir1/* dir2/ also atomic?

As an example, assume there are 10 files in dir1 that are 10GB each.

已采纳解答

原帖链接 · Chris Davies · CC BY-SA 4.0

Let's start with the statement that mv is not always atomic.

Let's also identify that atomicity refers to file contents, not to the file name.

For any individual file, the move or rename performed by mv is atomic provided that the file is moved within the same filesystem. The atomicity does not guarantee that the file is only in one place or another; it is quite possible that the file could be present in the filesystem in both places simultaneously for "a short time". What atomicity does guarantee, when offered, is that the file contents are instantaneously available completely and not partially. You can imagine that mv in such situations could have been implemented with ln followed by rm.

mv is most definitely not atomic when the move that it performs is from one filesystem to another, or when a remote filesystem cannot implement the mv operation locally. In these instances mv could be said to be implemented by the equivalent of a cp followed by rm.

Now, moving on to the question of atomicity across multiple files. mv is at best atomic only per file, so if you have a number of files to move together, the implementation is such that they will be moved one at a time. If you like, mv file1 dir; mv file2 dir; mv file3 dir.

If you really need a group of files to appear in a destination simultaneously, consider putting them in a directory and moving that directory. This single object (the directory) can be moved atomically.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-03-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。