General
cancel
Showing results for 
Search instead for 
Did you mean: 

Find inactive files and remove them

wojtek75
Frequent Advisor

Find inactive files and remove them

Hi,

I think I saw a 'find' command which uses 'fuser' and 'rm' subcommands in -exec parameters to remove all inactive (not opened by other processes) files. Does anybody remember that?
8 REPLIES
Dennis Handly
Acclaimed Contributor

Re: Find inactive files and remove them

This sounds very dangerous. I assume you are going to limit this removal to a specific directory tree?
wojtek75
Frequent Advisor

Re: Find inactive files and remove them

Sure, it is only on test machines.
Torsten.
Acclaimed Contributor

Re: Find inactive files and remove them

It sounds still dangerous.
What if an application is running, but newly opens a file for each access?

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
wojtek75
Frequent Advisor

Re: Find inactive files and remove them

I am aware of that. All I need is a command that makes it possible.
James R. Ferguson
Acclaimed Contributor

Re: Find inactive files and remove them

Hi:

I can't fathom why you want to remove all files that are "not opened by other processes" --- test server or not.

If your objective is to remove all files except in-use executables and shared libraries, a simple 'rm' should do. Executables and shared libraries that are in-use will be fail to be removed with a "text busy" error.

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: Find inactive files and remove them

What is the problem you are trying to solve? A typical HP-UX install has several thousand files, some are executables, some are configuration files, some are shared libraries, some are device files, and the list goes on and on. You can easily cripple your OS or worse, make the system completely unbootable. Or you can create endless problems when you patch your system or try to install new software that depends on these files.

If you are trying to regain some disk space, that is not the way to do it. You would first look at your filesystems and determine if any are more than 75% full. Then analyze the directories in these filesystems to determine if there are temporary files that can be removed. Then use swlist to look at the installed applications and subsystems to see if there are some that you do not plan to use. Again, do not swremove a product until you know what it does and whether other products depend on this fileset.

If the above list looks complicated and time consuming, you'd be correct. Adding more disks, or replacing small disks with larger disks is much simpler and you won't risk breaking the operating system.


Bill Hassell, sysadmin
wojtek75
Frequent Advisor

Re: Find inactive files and remove them

Hi,

I have many subdirectories with Oracle datafiles. All datafiles that are necessary for active instances are active (fuser returns processes). But many are just dumpfiles remaining from old instances partly removed (fuser returns no data). I just need a quick way to tidy it up on regular basis. The subdirectories may contain both active and inactive way.
James R. Ferguson
Acclaimed Contributor

Re: Find inactive files and remove them

Hi (again):

> All datafiles that are necessary for active instances are active (fuser returns processes). But many are just dumpfiles remaining from old instances partly removed (fuser returns no data).

You could use 'find -f' to collect the names of all files ("active" or not) into a file. Then, read the file of file names and apply an 'fuser' command to each file name:

# PIDS=$(fuser ${FILE} 2>/dev/null)

If the PIDS variable is empty, no processes are associated with the file, so remove it.

Regards!

...JRF...