Clean The /tmp Directory On Each Restart

The /tmp directory is my favorite place to extracting package, or to create dummy file. I Like using Wireshark and watching the traffic over my screen. I also place the capture file there, except for the one I needed to save for later read. Some application also save their temporary files at /tmp.

Someday I realized that my /tmp was very dirty so I decide to do a little cleaning. But why place a hand on it, if I can do it automatically??? :p

On OpenSUSE 11.0, my GNU/Linux installed distro, the script that will executed before shutdown is /etc/init.d/halt.local , so there is where we going. I add a simple command to delete the /tmp directory content,
rm -rf /tmp/{*,.??*}, and here is my /etc/init.d/halt.local file:

#! /bin/sh
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany.  All rights reserved.
# Author: Werner Fink <werner>, 1998
#         Burchard Steinbild, 1998
# /etc/init.d/halt.local
# script with local commands to be executed from init on system shutdown
# Here you should add things, that should happen directly before shuting
# down.
# clean the /tmp directory
/usr/bin/find /tmp/ -maxdepth 1 -regex '^/tmp/[.].*' -o -regex '^/tmp/[^.].*' | /usr/bin/xargs /bin/rm -rf

This time, I only need to clean the /tmp directory, maybe next time I’ll do something else with the script 🙂

Updated on Jan 3, 2009 @ 3:48
Change command from rm -rf /tmp/* to rm -rf /tmp/{*,.??*}
The previous command, rm -rf /tmp/* will let the hidden file or directory intact. So I add a little adjustment to delete the hidden file or directory. The command is rm -rf /tmp/.??* But this command will not delete the file or directory with 2 characters long name, e.g. .q and .u

Updated on April 29, 2009 at 5:46 pm
Now, I decide to use the command below to

/usr/bin/find /tmp/ -maxdepth 1 -regex '^/tmp/[.].*' -o -regex '^/tmp/[^.].*' | /usr/bin/xargs /bin/rm -rf

Clean The /tmp Directory On Each Restart

2 pemikiran pada “Clean The /tmp Directory On Each Restart

    1. slametyp berkata:

      Alo Kameichi,

      Dulu sempet juga sih pake Ethereal, tapi karena terganjal masalah hak paten (gitu deh…) namanya diganti jadi Wireshark.

      Sebenarnya ini terinspirasi dari sebuah cara untuk memanfaatkan partisi yang sama untuk swap di MS Windows dengan di GNU/Linux. Udah lama juga sih bacanya, sekitar awal 2000an gitu. Tapi nggak inget baca dimana… 😦 Prinsipnya, waktu boot GNU/Linux partisi tsb diformat menjadi partisi swap kemudian digunakan sebagaimana mestinya. Terus waktu reboot GNU/Linux partisi tsb diformat jadi FAT32 atau NTFS supaya bisa digunakan sebagai partisi khusus swap di MS Windows.

      Hehehe… Thanks Dude..

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s