Operating System - HP-UX
1820260 Members
2778 Online
109622 Solutions
New Discussion юеВ

Can I safely delete all files in /tmp

 
Andy Stout
Frequent Advisor

Can I safely delete all files in /tmp

The subject says it all. I'm a little scared to do anything to this server... it seems that whenever I ASSUME anything - something bad happens. I would ASSUME that I could empty /tmp and not worry about it - but I wanted to make sure with you all.

Just so you know, I've ordered some new books for HP-UX so maybe my volume of questions will back off a bit ;)
10 REPLIES 10
MarkSyder
Honored Contributor

Re: Can I safely delete all files in /tmp

/tmp should only be for temporary stuff (hence the name) but beware of developers who put stuff in there that's needed for a long time.

I have a cron job set up on my servers to delete anything over a week old in /tmp. It runs every Sunday. Make sure your developers aren't abusing /tmp and you should be able to do the same.

And don't let the questions back off - I read as many questions as I can, even if I can't answer them. I'm sure I learn more from other people's questions than I contribute in answers.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Ivan Ferreira
Honored Contributor

Re: Can I safely delete all files in /tmp

No, you can't just remove all files without control. There may be files that are in use.

Use the fuser command to find out if the files where used.

You can use the find /tmp -atime +7 -exec rm {} \; to delete files that where not accesed in 7 days. Use -mtime instead of atime to delete files that where not modified in 7 days.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ranjith_5
Honored Contributor

Re: Can I safely delete all files in /tmp

Hi Andy,

You can but depends somtimes on your applications as well. You can go ahead and delete any file which you find is not useful to you and those created on a previous date.

Same question is answered here:-

http://www.muug.mb.ca/pipermail/roundtable/2004-May/000617.html


Hope this helps.

Regards,
Syam
James R. Ferguson
Acclaimed Contributor

Re: Can I safely delete all files in /tmp

Hi Andy:

There are potentially some files in /tmp and in /var/tmp that hold information about processes on a current running instatiation so I'd be somewhat selective.

At your option, you can enable the startup scripts to empty '/tmp' and '/var/tmp' during the startup boot sequence.

Set 'CLEAR_TMP=1' in '/etc/rc.config.d/clean_tmps'

Regards!

...JRF...


john kingsley
Honored Contributor

Re: Can I safely delete all files in /tmp

Normally files in this directory are deleted during reboots. Some process do open temp files in this area while they are running. So, before you delete any file, you can make sure it isn't being used by running:

fuser -c
Pete Randall
Outstanding Contributor

Re: Can I safely delete all files in /tmp

Andy,

It's also common practice to clear /tmp on reboot by setting CLEAR_TMP to 1 in /etc/rc.config.d/clean_tmps.


Pete

Pete
Orhan Biyiklioglu
Respected Contributor

Re: Can I safely delete all files in /tmp

If you want to see which processes are currently accessing files under the /tmp install lsof from http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.76/

and type:

#/usr/local/bin/lsof | awk '$9 ~ /^\/tmp/{print}'

this will print out the processes and files they have open file handles to.

hth
Alzhy
Honored Contributor

Re: Can I safely delete all files in /tmp

For servers that are rarely rebooted, CLEAN_TMP obviously is not a good solution.

What we are doing instead is we use a combination of find and fuser - to make sure files that are marked for deletion are not currently in use. We also search for files with matching PIDs in the file names and skip them..



Hakuna Matata.
Borislav Perkov
Respected Contributor

Re: Can I safely delete all files in /tmp

Hi Andy,

You can't delete safely all files from /tmp directory. If your server is not rebooted for long time the best way is to execute the command:
find /tmp -atime +n -exec rm {} \;

from crontab, where n is number of days when the files ftom tmp are accessed.
Regards,
Borislav
Marvin Strong
Honored Contributor

Re: Can I safely delete all files in /tmp

If you delete all files in /tmp the files will go away, but the inodes will still be held by the processes that were using that file. So what you see from ls will not be entirely accurate. /tmp could have no files and still have xM used because of a processes holding open files.

A safer way to cleanup /tmp if it seems to be filling up is just run a cron that deletes everything thats x days old. a simple find command that runs daily and your /tmp should stay relatively clean.