I know in Linux, if we want to rename a folder from f_old
to f_new
, we can run:
我知道在Linux中,如果我们想将文件夹从f_old重命名为f_new,我们可以运行:
mv f_old f_new
But this command actually confuses me. Does the system copy all stuff inside f_old
, paste it to new folder f_new
and delete f_old
at last? Or does it just rename f_old
to f_new
?
但这个命令实际上让我很困惑。系统是否会复制f_old中的所有内容,将其粘贴到新文件夹f_new并最后删除f_old?或者只是将f_old重命名为f_new?
3 个解决方案
#1
7
Nothing gets copied or moved if the source and destination are on the same partition. Various inode components get manipulated, that's all. If the source and destination are different then you will see a physical copy and delete.
如果源和目标位于同一分区上,则不会复制或移动任何内容。各种inode组件都被操纵了,就是这样。如果源和目标不同,那么您将看到物理副本和删除。
Edit -
Note that it is the directory entries that are manipulated. This is a different thing from the inode.
请注意,它是被操纵的目录条目。这与inode不同。
#2
6
As long as the target location is on the same partition (filesystem) as the source, no data will get moved or even touched. Only the name in the directory entry gets changed.
只要目标位置与源相同的分区(文件系统),就不会移动甚至触摸任何数据。只更改目录条目中的名称。
If the target is on a separate partition, the data will first get copied to the target and then removed from source.
如果目标位于单独的分区上,则数据将首先复制到目标,然后从源中删除。
#3
4
This is covered in the full manual, which man mv
explains how to get:
完整的手册中对此进行了介绍,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'
This is also available online here: https://www.gnu.org/s/coreutils/mv
这也可以在线获取: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.
mv可以将任何类型的文件从一个文件系统移动到另一个文件系统。在fileutils的4.0版之前,mv只能在文件系统之间移动常规文件。例如,现在mv可以将整个目录层次结构(包括特殊设备文件)从一个分区移动到另一个分区。它首先使用cp -a使用的一些相同代码来复制请求的目录和文件,然后(假设复制成功)它删除了原件。如果复制失败,则删除复制到目标分区的部分。如果要将三个目录从一个分区复制到另一个分区,并且第一个目录的副本成功,但第二个目录没有,则第一个将保留在目标分区上,第二个和第三个将保留在原始分区上。
#1
7
Nothing gets copied or moved if the source and destination are on the same partition. Various inode components get manipulated, that's all. If the source and destination are different then you will see a physical copy and delete.
如果源和目标位于同一分区上,则不会复制或移动任何内容。各种inode组件都被操纵了,就是这样。如果源和目标不同,那么您将看到物理副本和删除。
Edit -
Note that it is the directory entries that are manipulated. This is a different thing from the inode.
请注意,它是被操纵的目录条目。这与inode不同。
#2
6
As long as the target location is on the same partition (filesystem) as the source, no data will get moved or even touched. Only the name in the directory entry gets changed.
只要目标位置与源相同的分区(文件系统),就不会移动甚至触摸任何数据。只更改目录条目中的名称。
If the target is on a separate partition, the data will first get copied to the target and then removed from source.
如果目标位于单独的分区上,则数据将首先复制到目标,然后从源中删除。
#3
4
This is covered in the full manual, which man mv
explains how to get:
完整的手册中对此进行了介绍,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'
This is also available online here: https://www.gnu.org/s/coreutils/mv
这也可以在线获取: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.
mv可以将任何类型的文件从一个文件系统移动到另一个文件系统。在fileutils的4.0版之前,mv只能在文件系统之间移动常规文件。例如,现在mv可以将整个目录层次结构(包括特殊设备文件)从一个分区移动到另一个分区。它首先使用cp -a使用的一些相同代码来复制请求的目录和文件,然后(假设复制成功)它删除了原件。如果复制失败,则删除复制到目标分区的部分。如果要将三个目录从一个分区复制到另一个分区,并且第一个目录的副本成功,但第二个目录没有,则第一个将保留在目标分区上,第二个和第三个将保留在原始分区上。