简体   繁体   English

为什么Linux mv命令可以同时操作文件和目录whitout选项-r?

[英]Why Linux mv command can operate both file and directory whitout option -r?

rm and cp command should use option -r to distinguish file and directory. rm 和 cp 命令应该使用选项 -r 来区分文件和目录。 I think it means that they operate file and directory in a different way?我认为这意味着他们以不同的方式操作文件和目录? However, mv command dosen't need it.但是, mv 命令不需要它。 This my problem.这是我的问题。 I want to understand how they work and their differences.And also, i want to know where do I go to find the answer the next time I have a similar problem?我想了解它们是如何工作的以及它们之间的区别。另外,我想知道下次遇到类似问题时我该去哪里找到答案?

My english is poor.我的英语很差。 Please forgive me if there are any mistakes.如有错误请见谅。 Any answer maybe helpful.任何答案都可能有帮助。 Thanks.谢谢。

You may picture a directory as a "list" of what it actually contains (rather than a physical folder).您可以将目录想象为它实际包含的内容的“列表”(而不是物理文件夹)。

When you move a directory to another place using mv , you simply need to move the reference to this list on the disk, the content remaining unchanged.当您使用mv将目录移动到另一个地方时,您只需将对该列表的引用移动到磁盘上,内容保持不变。

rm and cp , however, need to browse this list because each item inside it need to be processed individually.但是, rmcp需要浏览此列表,因为其中的每个项目都需要单独处理。 Thus the -r if they contain subdirectories.因此-r如果它们包含子目录。

If you have files in your folder and you want to copy or move it, you need to do the -r.如果您的文件夹中有文件并且想要复制或移动它,则需要执行 -r。 It means recursive, it copys/moves the folder and also the files inside the folder.这意味着递归,它复制/移动文件夹以及文件夹内的文件。

When you have a folder without any files inside, you don't need to put that -r in the code, because the folder is empty.当你有一个里面没有任何文件的文件夹时,你不需要把那个 -r 放在代码中,因为文件夹是空的。

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

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