1820540 Members
2902 Online
109626 Solutions
New Discussion юеВ

Re: List Open Files

 
FrankBurg
Occasional Advisor

List Open Files

Hi experts, I need to make a script to get (list) the open files in a file system. I need that because I have to remove a group of files, but not the open files.
Please, Can somebody help me.
Thanks.....
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: List Open Files

By far, the tool of choice for this task is "lsof" -- list open files; a much less powerful choice is the fuser command.

Get lsof from here:

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.77/

Lsof is such a useful command; no HP-UX box should leave /home without it.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: List Open Files

By the way, you can remove open files as well. For example, if you remove /xxx/yyy/myfile, the underlying unlink() system call will remove the directory entry and myfile will no longer be visible. However, the application will continue to access this file normally because the file will not actually be deleted until all process which had the file open either close the file or terminate.

Man 2 unlink for details.
If it ain't broke, I can fix that.
FrankBurg
Occasional Advisor

Re: List Open Files

The point is, I can't install any tools...I think that I have to use fuser, but Can you help with the parameters, to list the open files?
A. Clay Stephenson
Acclaimed Contributor

Re: List Open Files

It's not very complicated. For example "fuser /home/mydir" would list process that have files open under /home/mydir (or perhaps not open) but using it as the current working directory. I've given you the command so the rest of the quest should be up to you. man fuser for details.
If it ain't broke, I can fix that.
Calandrello
Trusted Contributor

Re: List Open Files

Friend
For the Glance you obtain this information .
florin_10
Frequent Advisor

Re: List Open Files


fuser -u /dev/dsk/cXtXdX will show all procs and related users on that disk.
The -k option will kill processes for a specific file(s) or file system.
Regards,
FLG
Bill Hassell
Honored Contributor

Re: List Open Files

fuser won't work because it does not find open files, it locates PIDs for processes that have enumerated filenames or directories or mounpoints. It does not name the files. If you cannot install lsof, your only choice is to run Glance and if that is not installed, you'll have to run fuser on each file you want to test. If it is open, fuser will return PID(s) for processes that have the file open.


Bill Hassell, sysadmin
jerry1
Super Advisor

Re: List Open Files

for i in `ls -R .`;do
if [ `fuser -u $i` ];then
echo $i >>filesopen
done 2>/dev/null
jerry1
Super Advisor

Re: List Open Files

fuser does list open files.

DESCRIPTION
The fuser command lists the process IDs of
processes that have each specified file
open.

o It has file open.
^

more somefile - in another window.

fuser -u somefile

somefile: 20483o(root)
^