Linuxtipstricks – Just another /linux/blog

December 13, 2008

How to find out who has a file open in Linux

Filed under: user tipstricks — Antonio Portuesi @ 1:28 pm
Tags: , , , , , , , , ,

How often do mounts and umounts operations fail because you cannot determine who or what is using that device? How many times can you not eject a DVD because someone or something has it still open? How many times have you experienced a file manager that keeps a directory open even after you have navigated out of that directory and clicked the refresh button several times?

Let’s use the fuser tool to find out soething useful for our purpose.

Example 1:

user@pc:~$ fuser -mu /home

/home:                5525c(user)  5601m(user)  5607c(user)  5614c(user)  5685c(user)  5739c(user)  5740c(user)  5742c(user)  5743cm(user)  5744cm(user)  5766m(user)  5778m(user)  5789c(user)  5795c(user)  5799c(user)  5801c(user)  5803cm(user)  5805cm(user)  5806m(user)  5921m(user)  6001cm(user)  6005cm(user)  6076(user)  9391cm(user)  9395c(user)

Example 2:

user@pc:~$ fuser -mu /media

/media:               5514rce(user)  5525re(user)  5586rce(user)  5587rce(user)  5593rce(user)  5595rce(user)  5601rce(user)  5604rce(user)  5607re(user)  5613rce(user)  5614re(user)  5617rce(user)  5685re(user)  5738rce(user)  5739re(user)  5740re(user)  5742re(user)  5743re(user)  5744re(user)  5747rce(user)  5757rce(user)  5759rce(user)  5762rce(user)  5766rce(user)  5772rce(user)  5778rce(user)  5789re(user)  5795re(user)  5799re(user)  5801re(user)  5803re(user)  5805re(user)  5806rce(user)  5811rce(user)  5921rce(user)  6001re(user)  6005re(user)  6032rce(user)  6071rce(user)  6076rce(user)  8712rce(user)  9391re(user)  9395re(user)

Now you get the owner and the related process id. For rurther information about a listed process you can research deeper using ps ax.

Advertisements

1 Comment »

  1. Nice.

    This is one of those things that stay unknown to even long time linux users.

    Comment by jrharshath — December 13, 2008 @ 2:22 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: