mv 是两个文件系统之间的原子操作吗?

Vas*_*wda 6 rename mv

通过mv命令在两个文件系统之间移动文件是原子操作吗?

ctr*_*l-d 11

查看 EXDEV 错误(在 man 2 rename 中):

   EXDEV  oldpath and newpath are not  on  the  same  mounted  filesystem.
          (Linux  permits  a  filesystem to be mounted at multiple points,
          but rename() does not work across different mount  points,  even
          if the same filesystem is mounted on both.)
Run Code Online (Sandbox Code Playgroud)

你不能通过系统调用在文件系统之间移动,所以 mv 所做的是用户空间复制和删除,这从来都不是原子的。

  • @ schily 您可以随时中断系统调用之间的进程。您的方法将如何进行原子移动? (2认同)