[PLUG] Open files
Rogan Creswick
creswick at gmail.com
Wed Nov 10 16:37:54 UTC 2004
On Wed, 10 Nov 2004 08:19:22 -0800, Michael Montagne
<michael at themontagnes.com> wrote:
> So, I'm switching my main office file server to Linux/Samba. One of
> the features I need is the one that list which users have which files
> open. the lsof command gives too much info and doesn't seem to list
> this sort of info anyway (I think). Any suggestions?
lsof | grep REG will filter out a lot of the info you don't want.
lsof <filename> will only return info about that file, likewise:
lsof /usr/bin/* ,for example will do what you would expect, so
combining find and some other magic, a line like this should do it:
find <root of interest> <possible file mask(s) w/ find magic> | xargs lsof
eg:
find / -name "*.txt" | xargs lsof
will give you all users with .txt files (and those files) open on your system
add some perl...
find / -name "*.txt" | xargs lsof |
perl -e 'foreach(<>){@fields = split(/\s+/); print "$fields[2] $fields[8]\n";}'
to get just the username & file (all one line--and there has to be a
shorter sollution...) I'm sure someone with a bigger perl hat can
easily work in a uniqueness check, so you only get one line / user.
HTH,
-Rogan
>
> --
> Michael Montagne
> michael at themontagnes.com
> http://www.themontagnes.com
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>
More information about the PLUG
mailing list