Freeing temp space

Posted on 2005-04-21
Last Modified: 2013-12-27
On my solaris machine the /tmp folder appears cluttered. To free up the space, can I delete the files and folders or should I followup a procedure to check if the files are being still in use.

Question by:wfaleiro
    LVL 48

    Accepted Solution

    A lot of systems use a cronjob to periodically clean out old files in /tmp and /var/tmp, eg:

    find /tmp /var/tmp -type f -mtime +7 -exec rm -f {} \;
    LVL 7

    Expert Comment

    From a programming standpoint, /tmp should be considered unreliable, and the contents could disappear at any time.  Unfortunately, this is not always respected, and potentially in-use files may be there.  Noteable examples include screen sessions and MySQL's socket.

    The find command referenced by Tintin is an excellent one for this purpose, as it will only delete files that were last modified no less than a week ago.  You may also wish to remove files based on name.  E.g. PHP has a habit of leaving session files laying around, and some user programs (especially KDE based) will often leave stale files that don't get deleted.  This may happen because of unexpected exits, sloppy programming, or any other number of reasons.

    Also, if the server is rebooted, the files in /tmp are safe to delete (before programs are restarted).  If you want to check if any files are actively open and in-use by a program, check with lsof.  Note, though, that a program may still want to access a file but not have an active file handle open for it.
    LVL 10

    Expert Comment

    macker: If the server is rebooted then /tmp is deleted, as /tmp is (by default) a ramdisk.

    I basically agree with tintin's solution, even though, for a very small chance there could be files not being modified for a week and still being needed.

    I personally "solved" this by rebooting the server when I apply the latest patchcluster (and by the reboot as said, the ramdisk is of course cleared). I know that this might not allways be possible, but if possible I think it's quite a good solution.
    LVL 7

    Expert Comment

    Ah, had not recalled that it's a ramdisk.  That certainly tidys things up.  In any regard, it sounds like Tintin's solution is the best by consensus.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Video by: Phil
    This video goes over how to configure and start a jail in FreeBSD.  This video is meant to supplement the article included with this course.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now