在 Linux 中如何找出哪个进程锁定了某个文件?
今天我遇到了无法删除文件夹的问题,因为“它很忙”。
我怎样才能找出应该归咎于哪个应用程序,或者我可以用暴力删除它?
Today I had the problem that I couldn't delete a folder because "it was busy".
How can I find out which application to blame for that or can I just delete it with brute force?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 lsof 找出哪些文件已打开。
man lsof 或看看这里
Use lsof to find out what has what files are open.
man lsof or have a look here
fuser
Unix 命令将为您提供进程访问文件。The
fuser
Unix command will give you the PIDs of the processes accessing a file.lslocks
列出了 Linux 系统中当前持有的所有文件锁的信息。 (util-linux 的一部分)该实用程序支持 json 输出,这对于脚本来说非常有用。lslocks
lists information about all the currently held file locks in a Linux system. (part of util-linux) this utility has support for json output, which is nice for scripts.fuser
将显示哪些进程正在访问文件或目录。fuser
will show you which processes are accessing a file or directory.