简体   繁体   English

为什么Linux中的rm命令可以在几秒钟内删除文件/目录,而FTP中的删除确实很慢

[英]Why rm command in Linux can delete file/dir in seconds while delete in FTP is really slow

Recently I created some dir which contains a lot of files and subdir by mistake. 最近,我创建了一些目录,其中包含很多文件和错误的子目录。 And then I tried to delete the dir through my FTP software (FileZilla), but it's really slow, like you can see it cost 2/3 seconds to delete each file. 然后,我尝试通过我的FTP软件(FileZilla)删除该目录,但这确实很慢,就像您看到要删除每个文件需要2/3秒一样。

So I stopped it and tried that through SSH and use rm -rf command, then the target directory was deleted just in a second. 所以我停止了它,并尝试通过SSH并使用rm -rf命令,然后仅在一秒钟内删除了目标目录。

My question is why it's so slow on FTP while fast on SSH? 我的问题是,为什么FTP这么慢,而SSH这么快?

Much thanks! 非常感谢!

To delete a directory tree, you have to iterate it, retrieve lists of all files and subdirectories, and delete them one by one. 要删除目录树,您必须对其进行迭代,检索所有文件和子目录的列表,然后逐个删除它们。

  • When you use the remote rm -rf command, it has a direct access to the file system, so it is relatively quick. 使用remote rm -rf命令时,它可以直接访问文件系统,因此速度相对较快。

  • While the FTP client has to retrieve the file lists (what involves couple of FTP command exchanges, opening data channel, listing transfer, etc) and then it has to delete the files one by one. FTP客户端必须检索文件列表(这涉及几个FTP命令交换,打开数据通道,列表传输等),然后它必须一个一个地删除文件。 Each delete involves sending the FTP command, waiting for the response. 每次删除都涉及发送FTP命令,等待响应。 So it takes long. 因此需要很长时间。

There's no "delete whole tree" command in FTP protocol that would be an equivalent of the rm -rf command executed on the remote shell. FTP协议中没有“删除整个树”命令,该命令等同于在远程shell上执行rm -rf命令。

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

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