Today’s Command Of The Day is the “fuser” command.
Have you ever wanted to unmounted an NFS share, or local filesystem and couldn’t because it was in use? The same applies to CD/DVD’s, PenDrives, etc. Generally, you receive a message similar to the following:
# umount /dev/sdc1
umount: /media/disk: device is busy.
The fuser has many options. The ones I use the most are “-cu”. The “u” option appends the username to the PID and the “c” option is the same as the “m” option, is what you use if you are telling it to check a file, filesystem, or mounted device.
# fuser -cu /dev/sdc1
/dev/sdc1: 8500c(gsmeiers)# ps u -p 8500
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
gsmeiers 8500 0.0 0.2 21588 4488 pts/3 Ss+ 08:25 0:00 bash
Here we see that /dev/sdc1 has one PID that is using it. A further ps shows what that PID is. You can specify either a device name or filesystem when using cu and it will work the same.
You can also, in some versions of fuser, specify a “-v” option to have it show the information about the processes it finds. For example:
$ fuser -cv /dev/sdc1
USER PID ACCESS COMMAND
/dev/sdc1: gsmeiers 7367 ..c.. bash
gsmeiers 8500 ..c.. bash
gsmeiers 9534 F.c.. vi
Fuser also has other commands — such as the “-k” command, which can kill all processes that are using a particular filesystem/device. Be careful with this one!
![[del.icio.us]](http://www.theunixzone.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.theunixzone.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.theunixzone.com/wp-content/plugins/bookmarkify/facebook.png)
![[Twitter]](http://www.theunixzone.com/wp-content/plugins/bookmarkify/twitter.png)