Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I tried to rm -rf a folder, and got "device or resource busy".

In Windows, I would have used LockHunter to resolve this. What's the linux equivalent? (Please give as answer a simple "unlock this" method, and not complete articles like this one. Although they're useful, I'm currently interested in just ASimpleMethodThatWorks™)

share|improve this question
1  
Thanks this was handy - I was coming from Linux to Windows, was looking for the equivalent of lsof - LockHunter. –  Sonia Hamilton Sep 4 '13 at 2:28
1  
What the hell? Unix does not prevent you from deleting open files like Windows does. This is why you can delete your whole system by running rm -rf /... it will happily delete every single file, including /bin/rm. –  psusi Oct 10 at 15:35

4 Answers 4

up vote 28 down vote accepted

The tool you want is lsof, which stands for list open files.

It has a lot of options, so check the man page, but if you want to see all open files under a directory:

lsof +D /path

That will recurse through the filesystem under /path, so beware doing it on large directory trees.

Once you know which processes have files open, you can exit those apps, or kill them with the kill(1) command.

share|improve this answer
    
What if there were no results? –  marines Feb 4 at 15:04
2  
@marines: Check if another filesystem is mounted beneath /path. That is one cause of hidden "open files". –  camh Feb 5 at 9:16

I use fuser for this kind of thing. It will list which process is using a file or files within a mount.

share|improve this answer
    
fuser helps only in the specific case when you want to unmount a filesystem. Here the problem is to find what's using a specific file. –  Gilles Apr 13 '11 at 19:09
    
@Gilles: Also works for files. –  BillThor Apr 14 '11 at 0:36
    
Sorry, wrong objection: fuser doesn't help here because the problem is to find all the open files in a directory tree. You can tell lsof to show all files and filter, or make it recurse; fuser has no such mode and needs to be invoked on every file. –  Gilles Apr 14 '11 at 7:57
    
@Giles: fuser works will lists. Try fuser /var/log/*, if any logs are open it will tell which ones and who has it open. If a simple wildcard, won't work, find with or without xargs will do the job. –  BillThor Apr 14 '11 at 17:23

sometimes it's the result of mounting issues, so I'd unmount the filesystem or directory you're trying to remove:

umount /path

share|improve this answer

Here is the solution:

  1. Go into the directory and type ls -a
  2. You will find a .xyz file
  3. vi .xyz and look into what is the content of the file
  4. ps -ef | grep username
  5. You will see the .xyz content in the 8th column (last row)
  6. kill -9 job_ids - where job_ids is the value of the 2nd column of corresponding error caused content in the 8th column
  7. Now try to delete the folder or file.
share|improve this answer
    
It would be interesting to know where those mysterious files are coming from. –  John WH Smith Aug 12 at 20:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.