題 為什麼命令mv返回消息mv:無法在Linux上移動設備或資源忙?


我試圖將文件從一個目錄移動到另一個目錄,並顯示以下消息,儘管文件已被移動。為什麼顯示“錯誤”,它是什麼意思?什麼時候發生?目錄位於同一設備和分區上。該設備運行Ubuntu 12.04 LTS

錯誤

*mv: cannot move `.' to `../new_media/press/.': Device or resource busy*

3
2017-12-28 06:12


起源




答案:


來自 rename(2) 手冊頁:

   EBUSY  The  rename fails because oldpath or newpath is a directory that
          is in use by some process (perhaps as current working directory,
          or  as root directory, or because it was open for reading) or is
          in use by the system (for example as  mount  point),  while  the
          system considers this an error.  (Note that there is no require‐
          ment to return EBUSY in such cases — there is nothing wrong with
          doing  the  rename anyway — but it is allowed to return EBUSY if
          the system cannot otherwise handle such situations.)

3
2017-12-28 06:52



謝謝。有沒有辦法判斷所說的“目錄”是否被其他進程使用? - PeanutsMonkey
如果你想要移動 . 那麼這是你當前的工作目錄,你應該離開它。 - Ignacio Vazquez-Abrams


某些進程正在使用文件/ s。您可以使用命令'lsof'(列出打開的文件)找到哪些文件被哪些進程打開。這將返回一個 批量 打開文件。一旦找到了這個過程,你就可以嘗試殺死它。

或者,如果這是一個選項,則重新啟動計算機可能會更容易。


2
2017-12-28 10:09