简体   繁体   English

Ubuntu mv 命令只复制了,但源文件仍然存在

[英]Ubuntu mv command only copied, but the source files still exist

I accidentally executed mv without ./ for my source folder.我不小心为我的源文件夹执行了没有 ./ 的 mv 。 It copied the files from the root folder, but did not remove them.它从根文件夹复制文件,但没有删除它们。

I checked some of the files that were copied into the new folder from root and it seems that they are still in the root as well as the new folder.我检查了一些从根目录复制到新文件夹中的文件,它们似乎仍在根目录和新文件夹中。 So I think the command did not move, but copied the files.所以我认为命令没有移动,而是复制了文件。 I just want to understand what exactly happened here.我只是想了解这里到底发生了什么。 Any ideas?有任何想法吗?

Here is the command I executed: bla:my/current/folder$ mv -v /* sub_folder/这是我执行的命令:bla:my/current/folder$ mv -v /* sub_folder/

You are copying from the root, as you can see, you are using from /* which means from the root filesystem to that subfolder. 如您所见,您正在从根目录进行复制,您正在使用从/*进行的复制,这意味着从根文件系统复制至该子文件夹。 And with an unprivileged user you can't do this because you can't write files outside of your home folder by default. 对于没有特权的用户,您将无法执行此操作,因为默认情况下您无法在主文件夹之外写入文件。

Just remove the / before the * and try again. 只需删除*之前的/然后重试。 Or add a dot before the / , eg: mv -v ./* sub_folder/ 或在/之前添加点,例如: mv -v ./* sub_folder/

I tested out the command and these are my findings.我测试了命令,这些是我的发现。

  1. mv has two phases 'copy' and 'remove'. mv 有两个阶段“复制”和“删除”。

  2. mv copies when the user has read access but fails to remove with no write access.当用户具有读访问权限但无法在没有写访问权限的情况下删除时,mv 会复制。

  3. If a mv process terminates while in its 'copy' phase none of the already copied files are removed.如果 mv 进程在其“复制”阶段终止,则不会删除任何已复制的文件。

  4. mv on a directory copies all files within the directory before recursively removing the directory. mv 在递归删除目录之前复制目录中的所有文件。 but if the target is a list of files( could be shell expansion) the 'remove' phase is run right after each 'copy' and not after all listed files have been copied.但如果目标是文件列表(可能是外壳扩展),则“删除”阶段会在每次“复制”之后运行,而不是在所有列出的文件都已复制之后运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM