Cp

為什麼 mv 比 cp 快那麼多?如何從不正確的 mv 命令中恢復?

  • May 16, 2021

我在 FileZilla 中錯誤地將一個文件夾拖放到另一個文件夾中。

~/big_folder
~/some_other_folder

被移動的文件夾是一個非常大的文件夾。它包括數十萬個文件(node_modules、小圖像文件、很多文件夾)

奇怪的是,當我鬆開滑鼠後,移動就完成了。文件夾“big_folder”移動到“some_other_folder”。

~/some_other_folder/big_folder

(搬家後big_folder沒有)~/

然後我意識到錯誤並嘗試向後移動,但它在 FileZilla 和終端上都失敗了。

然後我必須cp -r將文件複製回來,因為有伺服器端程式碼訪問這些文件~/big_folder

它需要永遠等待……

我該怎麼辦?

順便說一句,這是 FileZilla 的輸出(這是向後移動的失敗):

Status:       Renaming '/root/big_folder' to '/root/some_other_folder/big_folder'
Status:       /root/big_folder -> /root/some_other_folder/big_folder

Status:       Renaming '/root/some_other_folder/big_folder' to '/root/big_folder'
Command:  mv "big_folder" "/root/big_folder"
Error:          mv /root/some_other_folder/big_folder /root/big_folder: received failure with description 'Failure'

如果一個目錄在同一個文件系統(同一個分區)中移動,那麼只需要重命名該目錄的文件路徑。除了目錄本身的目錄條目之外,無需更改任何數據。

複製目錄時,需要複製每個文件的數據。這涉及讀取所有源數據並將其寫入目標。

在文件系統之間移動目錄將涉及將數據複製到目標並將其從源中刪除。這將花費大約與在單個文件系統中複製(複製)數據一樣長的時間。


如果 FileZilla 成功將目錄從 重命名~/big_folder~/some_other_folder/big_folder,那麼我將使用

mv ~/some_other_folder/big_folder ~/big_folder

…在首先確保沒有呼叫目錄之後~/big_folder(如果有,移動將作為子文件夾放入目錄big_folder中)。some_other_folder``~/big_folder

引用自:https://unix.stackexchange.com/questions/454318