Linux 的 mv 在内部是如何工作的?
How does Linux's mv work internally?
我知道 Linux,如果我们想将文件夹从 f_old
重命名为 f_new
,我们可以 运行:
mv f_old f_new
但是这个命令实际上让我感到困惑。系统会复制f_old
里面的所有东西,粘贴到新文件夹f_new
,最后删除f_old
吗?还是只是将 f_old
重命名为 f_new
?
只要目标位置与源位于同一分区(文件系统)上,就不会移动甚至触及任何数据。仅更改目录条目中的名称。
如果目标位于单独的分区上,数据将首先复制到目标,然后从源中删除。
完整手册中对此进行了介绍,man mv
解释了如何获取:
The full documentation for mv is maintained as a Texinfo manual. If
the info and mv programs are properly installed at your site, the comâ
mand
info coreutils 'mv invocation'
也可以在这里在线获得:https://www.gnu.org/s/coreutils/mv
mv can move any type of file from one file system to another. Prior to
version 4.0 of the fileutils, mv could move only regular files between
file systems. For example, now mv can move an entire directory
hierarchy including special device files from one partition to
another. It first uses some of the same code that's used by cp -a to
copy the requested directories and files, then (assuming the copy
succeeded) it removes the originals. If the copy fails, then the part
that was copied to the destination partition is removed. If you were
to copy three directories from one partition to another and the copy
of the first directory succeeded, but the second didn't, the first
would be left on the destination partition and the second and third
would be left on the original partition.
如果源和目标位于同一分区,则不会复制或移动任何内容。各种 inode 组件被操纵,仅此而已。如果源和目标不同,那么您将看到一个物理副本并删除。
编辑 -
请注意,它是 目录条目 被操纵的。这与 inode 不同。
我知道 Linux,如果我们想将文件夹从 f_old
重命名为 f_new
,我们可以 运行:
mv f_old f_new
但是这个命令实际上让我感到困惑。系统会复制f_old
里面的所有东西,粘贴到新文件夹f_new
,最后删除f_old
吗?还是只是将 f_old
重命名为 f_new
?
只要目标位置与源位于同一分区(文件系统)上,就不会移动甚至触及任何数据。仅更改目录条目中的名称。
如果目标位于单独的分区上,数据将首先复制到目标,然后从源中删除。
完整手册中对此进行了介绍,man mv
解释了如何获取:
The full documentation for mv is maintained as a Texinfo manual. If
the info and mv programs are properly installed at your site, the comâ
mand
info coreutils 'mv invocation'
也可以在这里在线获得:https://www.gnu.org/s/coreutils/mv
mv can move any type of file from one file system to another. Prior to version 4.0 of the fileutils, mv could move only regular files between file systems. For example, now mv can move an entire directory hierarchy including special device files from one partition to another. It first uses some of the same code that's used by cp -a to copy the requested directories and files, then (assuming the copy succeeded) it removes the originals. If the copy fails, then the part that was copied to the destination partition is removed. If you were to copy three directories from one partition to another and the copy of the first directory succeeded, but the second didn't, the first would be left on the destination partition and the second and third would be left on the original partition.
如果源和目标位于同一分区,则不会复制或移动任何内容。各种 inode 组件被操纵,仅此而已。如果源和目标不同,那么您将看到一个物理副本并删除。
编辑 -
请注意,它是 目录条目 被操纵的。这与 inode 不同。