26

I'm trying to delete /var/www/html but I'm getting this error:

rm: cannot remove `html': Device or resource busy
Hugo
  • 261
  • 1
  • 3
  • 3

3 Answers3

29

I was having the same issue, I was trying and failing to delete

/usr/local/tomcat/data

with the error rm: cannot remove/usr/local/tomcat/data': Device or resource busy`

until I noticed that df -h said

/dev/vda3              20G  172M   20G   1% /usr/local/tomcat/data

that is, I had a partition mounted to that point. Mystery solved.

annaken
  • 411
  • 4
  • 5
  • 1
    If you want to actually unmount the partition, see advice in this comment: https://unix.stackexchange.com/questions/11238/how-to-get-over-device-or-resource-busy#comment821528_11241 – Jake Levi Aug 12 '21 at 13:05
11

You can use lsof or fuser to indentify which is using this directory, something like this:

# lsof +D /var/www/html
quanta
  • 50,327
  • 19
  • 152
  • 213
4

It's likely that there is a process running that is using a file or files found somewhere in the tree below /var/www/html

try

lsof +D /var/www/html

to get a list of the processes using files in the tree. Sample output below shows that a bash shell with PID 8138 is using /var/www/html/iain.

COMMAND  PID USER   FD   TYPE DEVICE SIZE    NODE NAME
bash    8138 iain  cwd    DIR  253,0 4096 1982790 /var/www/html/iain
user9517
  • 114,104
  • 20
  • 206
  • 289