Operating System - HP-UX
1819870 Members
2352 Online
109607 Solutions
New Discussion юеВ

Delete files from /tmp and /var/tmp

 
SOLVED
Go to solution
KRI
Advisor

Delete files from /tmp and /var/tmp

Hi !

How to safely delete files from /tmp and /var/tmp ?
On my system are running Informix, Tuxedo, MQSeries.

Thx
KRI
8 REPLIES 8
Clemens van Everdingen
Honored Contributor

Re: Delete files from /tmp and /var/tmp

Hi,

See this similar thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x86a4ba808b46d611abda0090277a778c,00.html

C.
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
John Palmer
Honored Contributor

Re: Delete files from /tmp and /var/tmp

Hi,

Normal practise is to run a regular cron job (probably daily) that removes files older than a certain number of days.

For example, the following command will delete all files in /tmp that are more than 7 days old:-

find /tmp -type f -mtime +6 -exec rm -f {} \;

Regards,
John
Emiel van Grinsven
Valued Contributor

Re: Delete files from /tmp and /var/tmp

Hi,

check for files still in use (don't delete them ofcourse) and the last acces time.
If files haven't been accessed for say 7 days, I would think it's safe to delete them.
It depends on what kind of files they are and on how much space you have avainlable.
if more space is available, delete them later.

Grt, E.
Santosh Nair_1
Honored Contributor

Re: Delete files from /tmp and /var/tmp

Theoretically all the files in /tmp and /var/tmp are supposed to be temporary files and so if they're not currently in use, can/should be deleted. You can find out if a file is in use by using the fuser command.

Typically we run a script through cron which scan /tmp and /var/tmp for files older than 7 days. If these files are not in use, then delete them. There have been no complaints yets.


Hope this helps.

-Santosh
Life is what's happening while you're busy making other plans
Steven Sim Kok Leong
Honored Contributor
Solution

Re: Delete files from /tmp and /var/tmp

Hi,

I would suggest that you remove files in /var/tmp or /tmp in an /sbin/rc1.d startup script.

Early during your system initialisation and startup, your applications are not launched yet, thus it would be safe to remove files in these directories. Thus I would suggest that you link your script in /sbin/rc1.d.

If you are to remove files in these directories while in run-level 3 or beyond, you may risk removing files that are still being opened by existing processes.

If you do not wish to wait for the next system startup, you can perform an fuser on the device mounted on by /tmp or /var/tmp to identify opened processes still using files in these directories. You can also use the lsof tool to provide finer granularity in identifying the processes currently using these directories. Subsequently, gracefully terminate these processes (only if not required) before removing the files.

Hope this helps. Regards.

Steven Sim Kok Leong
Emiel van Grinsven
Valued Contributor

Re: Delete files from /tmp and /var/tmp

Hi,

i just wonder... how often do you reboot the machine? I would go for a thorough analysis on what files come in these dirs and then create a cron job. Do as you think is best :-)

Grt, Emiel
Steven Sim Kok Leong
Honored Contributor

Re: Delete files from /tmp and /var/tmp

Hi,

Regardless of whether you are removing files in /tmp during a system reboot (how conscientious are you in installing kernel patches?), automated cron job or manual deletion, the main point is to check that residing file(s) are not in use during the deletion of such file(s).

In my environment, /tmp and /var/tmp don't usually fill up that fast. As such, a periodic deletion (eg. 7 days)is an overkill for me. Apart from deletion during system reboot, a cron script monitors when either of /tmp or /var/tmp is >80% full. When that occurs, I get paged and files in /tmp are selectively and manually removed.

Hope this helps. Regards.

Steven Sim Kok Leong
John Palmer
Honored Contributor

Re: Delete files from /tmp and /var/tmp

Steven,

I'm not sure that I'd agree with the need to check that temp files are in use.

The very fact that the 'modified date' is over a certain number of days old usually means that the file is not in use and even if a process still has the file open, deleting it doesn't affect that process. The file remains (unlinked and invisible) until it gets closed.

As others have stated, a startup script is fine but we now have very few servers that are regularly rebooted.

I prefer a cron'd daily housekeeping script which can be tailored to tidy other directories as well.

Regards,
John