A Short Script to Clean Your /tmp

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

A Short Script to Clean Your /tmp

#1 Post by Dougal »

As I mentioned in another thread, in Puppy2.00 and 2.0.1 the there are hidden files that don't get deleted from /tmp, don't show in rox and don't get counted when free-space is checked -- thus your pup_save gets filled without you knowing it.

A few days after cleaning it, I checked the /tmp folder again and there were already quite a lot of files there.
Here's what to do to check and clean in (the script is at the end):

- Boot into ram (there are files in /tmp that I don't think should be deleted while running...).
- Mount (with pmount or mut) the partition (hda4 in my case) containing the pup_save file.
- Manually mount the pup_save file:

Code: Select all

mount -o loop /mnt/hda4/pup_save.3fs /mnt/data
(as you can see I'm mounting it on /mnt/data -- completely arbitrary)
- now move into the /tmp folder (cd /mnt/data/tmp) and try deleting hidden files:

Code: Select all

rm -f .*
(notice the dot before the asterisk)(if you're afraid of deleting, you can use "ls", to try and list the hidden files)
- If you've got many hidden files there, you'll get an error message:

Code: Select all

rm : argument list too long
In such a case you can copy the text below into a script -- say, /root/clean.sh -- and run it

Code: Select all

./clean.sh
(You'll need to modify the FOLDER parameter at the top if you mounted somewhere else than /mnt/data)

The script:

Code: Select all

#!/bin/bash
FOLDER=/mnt/data/tmp

search_and_delete()
{
for SYM in 1 2 3 4 5 6 7 8 9 0 _ - . a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
do
rm -rf "$1""$SYM"*

if [ $? != "0" ];then
	NAME="$1""$SYM" 
	echo "checking "$NAME"*"
        search_and_delete "$NAME"
fi

done
}

cd $FOLDER
NAME="."
search_and_delete $NAME
exit
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#2 Post by Dougal »

I mistyped something. Fixed it now in the message above.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

jeffrey
Posts: 168
Joined: Mon 16 Jan 2006, 04:20
Location: Christchurch, New Zealand

Dangerous commands

#3 Post by jeffrey »

That looks dangerous to me.
Don't recommend "rm -f .*" because someone might type "rm -rf .*" and that would include .. which is the parent directory. Much safer to use the explicit "rm -f /tmp/*" or at least "rm -f .??*" (to avoid including "..").
Your script may attempt an "rm -rf .." which will clean up more than your /tmp directory!
Also if your cd fails but doesn't stop the script the "rm -rf" is again dangrous.
A better, safer, simpler solution (replacing the whole of your script) would be:

Code: Select all

find /mnt/data/tmp -type f -print | xargs rm -f

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

Re: Dangerous commands

#4 Post by Dougal »

jeffrey wrote:That looks dangerous to me.
Don't recommend "rm -f .*" because someone might type "rm -rf .*" and that would include .. which is the parent directory. Much safer to use the explicit "rm -f /tmp/*" or at least "rm -f .??*" (to avoid including "..").
Your script may attempt an "rm -rf .." which will clean up more than your /tmp directory!
Also if your cd fails but doesn't stop the script the "rm -rf" is again dangrous.
A better, safer, simpler solution (replacing the whole of your script) would be:

Code: Select all

find /mnt/data/tmp -type f -print | xargs rm -f
1) I suggested that if people are afraid they use "ls"
2) I actually used "rm -rf" and nothing happened
3) If you try running the script you'll see at the begining you get warnings about not being able to delete "." and ".."
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#5 Post by BarryK »

Note that this will be fixed for 2.02. At least, I intend to.
I am planning to delete /tmp/ from initrd script at bootup, rather than at
shutdown due to unionfs issues.

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#6 Post by Dougal »

BarryK wrote:Note that this will be fixed for 2.02. At least, I intend to.
I am planning to delete /tmp/ from initrd script at bootup, rather than at
shutdown due to unionfs issues.
I was thinking it might be easiest to do at bootup -- delete and then remake it.
The files clogging it are actually unionfs files, as far as I can tell.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

Post Reply