How to Fix the Device or Resource Busy Error on Linux
-
Use
lsof
to Find Open Files in a Certain Directory in Linux - Alternative Method in Fixing the Device or Resource Busy Error on Linux
This tutorial will fix the device or resource busy error in Linux. But first, let’s understand what device or resource busy is.
Some directories cannot be deleted if the device or resource is busy. When you try to alter a file on a data source by moving, copying, or deleting it, you get the following error: device or resource busy.
Use lsof
to Find Open Files in a Certain Directory in Linux
The program lsof
, which stands for list open files
, will be required. There are various ways to utilize this tool, and one of them is to find open files in a certain directory.
$ lsof +D /path
Output:
chrome 39483 39488 GpuMemory user mem REG 8,5 285840 11410830 /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0
chrome 39483 39488 GpuMemory user mem REG 8,5 678064 11411469 /usr/lib/x86_64-linux-gnu/libpixman-1.so.0.38.4
chrome 39483 39488 GpuMemory user mem REG 8,5 1065824 11411080 /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0.20600.4
chrome 39483 39488 GpuMemory user mem REG 8,5 41152 11411707 /usr/lib/x86_64-linux-gnu/libthai.so.0.3.1
chrome 39483 39488 GpuMemory user mem REG 8,5 112960 11410855 /usr/lib/x86_64-linux-gnu/libfribidi.so.0.4.0
chrome 39483 39488 GpuMemory user mem REG 8,5 85448 11411836 /usr/lib/x86_64-linux-gnu/libwayland-server.so.0.1.0
chrome 39483 39488 GpuMemory user mem REG 8,5 39448 11410444 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
chrome 39483 39488 GpuMemory user mem REG 8,5 26800 11410422 /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0
chrome 39483 39488 GpuMemory user mem REG 8,5 18688 11410411 /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0
chrome 39483 39488 GpuMemory user mem REG 8,5 709496 11409861 /usr/lib/x86_64-linux-gnu/libsystemd.so.0.28.0
chrome 39483 39488 GpuMemory user mem REG 8,5 101320 11411551 /usr/lib/x86_64-linux-gnu/libresolv-2.31.so
After running this command, you will be rescued through the file system under /path
, so it is best to perform it under huge directories.
You can exit those programs or kill them with the kill
command after you’re aware of the processes that have files open.
Alternative Method in Fixing the Device or Resource Busy Error on Linux
Type the following command into that directory to see what’s there.
$ls -a
Output:
. .. destination source
Look into the contents of the file with vi
.
$ vi destination source
Output:
" ============================================================================
" Netrw Directory Listing (netrw v165)
" /home/user/user/aven/destination
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:special
" ==============================================================================
../
./
thanosdir/
thanosdir2/
thanosdir4/
thanos.txt
thanos1.txt
thanos2.txt
~
You’ll notice that, due to an error, the data in the eighth column was messed up. The ps-ef
command can find the process PID
.
$ ps -ef | grep thanos1.txt
Output:
user 44317 38941 0 22:10 pts/0 00:00:00 grep --color=auto thanos1.txt
As mentioned, the output contains the PID
. We can kill that process by using kill PID
.