LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   what to do with files in /tmp (https://www.linuxquestions.org/questions/linux-general-1/what-to-do-with-files-in-tmp-480380/)

Valkyrie_of_valhalla 09-04-2006 03:45 PM

what to do with files in /tmp
 
My /tmp folder currently has 3,5 Gb! I just found this out when I was browsing in my computer, to see what takes up so much space.

Ok, so this should theoretically be a folder where programs store temporary files, and delete them automatically after a while, right?

Well, in a folder in /tmp called kde-myusername I currently have, stored as *.tmp files:

- most of the stuff I previewed in Ark, athough the archives they were originating from have been deleted a few months ago
- pictures, pdf's and web pages that I viewed in konqueror
- all log files of konqueror crashes
- about 20 files called amarok followed by various letters and numbers, containing only
Quote:

bt
echo \n\n
bt full
echo \n\n
echo ==== (gdb) thread apply all bt ====\n
thread apply all bt
I use amarok as an mp3 player, but I have no idea what these files are.
- and, what takes up most space, all the video clips I have stored on cd's that I have ever viewed using various movie players, mostly kaffeine. There are mostly only parts of the clips.

This are probably more newbie questions, but still I am asking it here.
1. Does it HAVE to store all these files?
2. Can I configure it to delete what it doesn't need anymore automatically? Or do I have to delete the files manually every time? If so, what do I do, just delete every *.tmp file there?
3. I also have 2 .xkm files in there. What are these used for?

Any help/info is appreciated. Thank you for reading this.

Tinkster 09-04-2006 04:11 PM

Quote:

Originally Posted by Valkyrie_of_valhalla
My /tmp folder currently has 3,5 Gb! I just found this out when I was browsing in my computer, to see what takes up so much space.

Ok, so this should theoretically be a folder where programs store temporary files, and delete them automatically after a while, right?

Well, in a folder in /tmp called kde-myusername I currently have, stored as *.tmp files:

- most of the stuff I previewed in Ark, athough the archives they were originating from have been deleted a few months ago
- pictures, pdf's and web pages that I viewed in konqueror
- all log files of konqueror crashes
- about 20 files called amarok followed by various letters and numbers, containing only

I use amarok as an mp3 player, but I have no idea what these files are.
- and, what takes up most space, all the video clips I have stored on cd's that I have ever viewed using various movie players, mostly kaffeine. There are mostly only parts of the clips.

This are probably more newbie questions, but still I am asking it here.
1. Does it HAVE to store all these files?
2. Can I configure it to delete what it doesn't need anymore automatically? Or do I have to delete the files manually every time? If so, what do I do, just delete every *.tmp file there?
3. I also have 2 .xkm files in there. What are these used for?

Any help/info is appreciated. Thank you for reading this.

Commonly /tmp gets cleaned out on a reboot. If your machine is up
24/7 you'll have to start thinking about house-keeping yourself...

Answering #1)
No, it doesn't.

#2)
A script run from a cron-job will be fine. I'd suggest something that
makes sure the files you're about to delete aren't being used anymore.
find -atime +7 -type f -exec rm -rf {} \;
will be fine.

#3)
no idea - pass. Did you ask google, our best friend?


Cheers,
Tink

Valkyrie_of_valhalla 09-04-2006 04:53 PM

Thanks for the quick reply.

No, I don't keep my machine up 24/7. I close it every night, but it doesn't seem to clean /tmp at a reboot or shutdown.

I was thinking about cron too, if there is no other way.
One more question. What do the parameters after rm do? ( -rf {} \; ) the man pages don't offer much info.
Isn't there a program that does this at boot time or shutdown, when no programs that might use it are running?

Also, I'm a bit afraid to remove everything in temp, even the files that haven't been used for a while, because of numerous people who claim that they deleted a file in /tmp and Linux got messed up, and none ever figured out why that happened. Maybe I'm just paranoid. I want to also find out first why it still keeps files last accessed over 6 months ago.

The .xkm file, according to dear ol' google is a "compiled keymap file", generated by a program called xkbcomp, which I don't seem to have installed.

Any ideas anyone?

TSquaredF 09-04-2006 07:04 PM

I had the same problem. I added a line to my shutdown script:

rm -rf /tmp/* /var/tmp/*

This gets rid of all 'visible' files whenever the machine is shut down.
I have had no problems with deleting it all.
Regards,
Bill

Valkyrie_of_valhalla 09-05-2006 11:27 AM

Thanks, I'll just put them in the trash and see what happens, then if nothing bad happens, I'll just write a cron job or something.

jlliagre 09-05-2006 11:56 AM

Quote:

Originally Posted by TSquaredF
I had the same problem. I added a line to my shutdown script:

rm -rf /tmp/* /var/tmp/*

This gets rid of all 'visible' files whenever the machine is shut down.
I have had no problems with deleting it all.

While removing files in /tmp is ok, /var/tmp is designed to store temporary files that need to preserved between reboots, for example editor recover files, the application is responsible to clean these files when no longer required, so you should be careful when cleaning /var/tmp.

Valkyrie_of_valhalla 09-05-2006 03:54 PM

ok, thanks, I'll just leave /var/tmp alone, as it doesn't occupy much space...
My main concern is just /tmp. As long as nothing can go wrong there, it's ok.

Tinkster 09-05-2006 05:53 PM

Quote:

Originally Posted by Valkyrie_of_valhalla
Thanks for the quick reply.

No, I don't keep my machine up 24/7. I close it every night, but it doesn't seem to clean /tmp at a reboot or shutdown.

I was thinking about cron too, if there is no other way.
One more question. What do the parameters after rm do? ( -rf {} \; ) the man pages don't offer much info.

-exec " <command> <commands params> {} \; "
Think of it as grouped like this.
-exec tells find to run command & params against anything it
found; {} is the placeholder for the path&name of the matching
results; \; is an escaped ; that terminates the exec, the \ is there
so the shell doesn't think it's a command-separator.

Quote:

Originally Posted by Valkyrie_of_valhalla
Isn't there a program that does this at boot time or shutdown, when no programs that might use it are running?

Depends on the distro you're running. Slackware leaves that
kind of activity to the discretion of the root user; Debian (and
most of its derivates) will have an /etc/init.d/bootclean that's
run during startup after mounting the file-systems. It's been
too long that I last actively used any dead-rat based distro to
be able to tell you how they do it :} and I can't get to the SuSE
machines at work from home ;}



Cheers,
Tink

Valkyrie_of_valhalla 09-06-2006 11:23 AM

Thanks again.

I looked in /etc/init.d and it does have a script called boot.clean, and, according to my low knowledge of shell scripting, it does remove some of the files in /tmp, but not all, specifically not the ones in /tmp/kde-dark (where dark is my username), or /tmp/kde-root (but that folder is mostly empty anyway,as I don't spend much time as root).

Anyway, for the ones curious enough, and patient enough to read, this is what that script contains:

Quote:

#! /bin/sh
#
# Copyright (c) 2001-2005 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# /etc/init.d/boot.cleanup
#
### BEGIN INIT INFO
# Provides: boot.cleanup
# Required-Start: boot.localfs
# Should-Start: boot.quota
# Required-Stop:
# Default-Start: B
# Default-Stop:
# Description: do cleanup
### END INIT INFO

. /etc/rc.status
. /etc/sysconfig/cron

rc_reset

case "$1" in
start)
#
# clean up
#
rm -f /var/lib/rpm/__db*
rm -rf /tmp/screens /tmp/uscreens /var/run/screens /var/run/uscreens 2>/dev/null
rm -f /tmp/.X*lock /var/spool/uucp/LCK* /fsck_corrected_errors 2>/dev/null
if test -x /usr/bin/find -a -x /usr/bin/xargs ; then
find /tmp/ssh-* -type s -name "*agent*" -maxdepth 1 -print0 2>/dev/null | xargs -0 -r rm -f
find /var/run /var/lock -type f -print0 | xargs -0 -r rm -f 2>/dev/null
else
# fallback for find if we get /usr from nfs
rec_rem() {
for f in "$1"/*
do
test -L "$f" && continue
test -f "$f" && rm -f "$f"
test -d "$f" && rec_rem "$f"
done
}
#
test -d /var/run && rec_rem /var/run
test -d /var/lock && rec_rem /var/lock
fi
: > /var/run/utmp
chmod 664 /var/run/utmp
chown root:tty /var/run/utmp
# Restore a possibly dynamically modified /etc/resolv.conf
if ls /etc/resolv.conf.saved.by.* &>/dev/null ; then
echo "Cleaning up using /sbin/modify_resolvconf:"
/sbin/modify_resolvconf cleanup
echo -e "$rc_done_up"
fi
# delete temp files
# If $CLEAR_TMP_DIRS_AT_BOOTUP = yes, delete files in
# $TMP_DIRS_TO_CLEAR, if $CLEAR_TMP_DIRS_AT_BOOTUP starts with a "/"
# delete files in those dirs instead.
CLEAR_DIRS="$TMP_DIRS_TO_CLEAR"
if [ "${CLEAR_TMP_DIRS_AT_BOOTUP:0:1}" = "/" ]; then
CLEAR_DIRS="$CLEAR_TMP_DIRS_AT_BOOTUP"
CLEAR_TMP_DIRS_AT_BOOTUP=yes
fi
if test -x /usr/bin/find -a -x /usr/bin/xargs ; then
if test "$CLEAR_TMP_DIRS_AT_BOOTUP" = yes; then
echo -n "Cleaning temporary directories $CLEAR_DIRS"
for CURDIR in $CLEAR_DIRS ; do
find $CURDIR -maxdepth 1 -printf '%P\0' | ( cd $CURDIR ; xargs -0 rm -rf -- )
done
rc_status -v -r
fi
fi
for CURDIR in /tmp /tmp/.X11-unix /tmp/.ICE-unix \
/var/tmp /var/tmp/vi.recover /var/run/uscreens ; do
test -d $CURDIR || \
mkdir $CURDIR && \
chown root:root $CURDIR && \
chmod 1777 $CURDIR
done
for CURDIR in /var/run/screens ; do
test -d $CURDIR || \
mkdir $CURDIR && \
chown root:root $CURDIR && \
chmod 755 $CURDIR
done

#
# there could be a new kernel version. reinit /etc/psdevtab, to be sure.
#
rm -f /etc/psdevtab
test -x /bin/ps && /bin/ps > /dev/null 2> /dev/null
;;
stop|restart)
# skip / nothing to do
;;
status)
rc_failed 4
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

rc_exit

Now, another question. Is every script in /etc/init.d executed at boot, or is there a config file or a specific shell script that executes only some of them?
While trying to find an answer for myself, I found /etc/init.d/README, which has this statement: " After system startup, /sbin/init will normally switch on the default run level given in /etc/inittab. It calls the run level master script /etc/init.d/rc to start or stop services provided by the other scripts under /etc/init.d/.
Both scripts, then boot level master script /etc/init.d/boot and the the run level master script /etc/init.d/rc starts all other boot or runlevel scripts either sequential or partial parallel within their dependencies order."

I took a fast look in all the scripts/files mentioned, but none seemed to execute boot.cleanup. I will look more in detail in them, taking the scripts line by line to understand how it works one of the following days.

I also think I am an idiot for not checking when boot.cleanup was last accessed before opening it with kwrite. But I'll look if it will have been accessed when I will reboot my computer.

Anyway, does anyone know a quick answer to this? What do I have to edit for a script to be executed at startup?

Sorry for the long post. Any ideas anyone?

jlliagre 09-06-2006 12:20 PM

Quote:

Originally Posted by Valkyrie_of_valhalla
Now, another question. Is every script in /etc/init.d executed at boot, or is there a config file or a specific shell script that executes only some of them?

No script in /etc/init.d is directly executed, this directory is simply a convenient place to have real rc scripts linked to.
Reals rc scripts are in directories named rc2.d rc3.d etc, and starts with either an uppercase S or an uppercase K.

magnus.therning 09-07-2006 02:41 AM

Quote:

Originally Posted by Valkyrie_of_valhalla
Thanks, I'll just put them in the trash and see what happens, then if nothing bad happens, I'll just write a cron job or something.

If you reboot your machine regularly you might want to look into mounting a tmpfs filesystem on /tmp.

Dr_Death_UAE 09-07-2006 03:40 AM

check if this line (clear_tmp_enable="YES")is in /etc/rc.conf

you can add a command to crontab to clear the /tmp:

*/120 * * * * root cd /tmp;rm *

jlliagre 09-07-2006 04:51 AM

Quote:

Originally Posted by Dr_Death_UAE
you can add a command to crontab to clear the /tmp:

*/120 * * * * root cd /tmp;rm *

Ouch !

Never do that.

Edit: I hope everyone understand why, as I had no reaction to this post ...

Valkyrie_of_valhalla 09-07-2006 11:04 AM

Quote:

Originally Posted by jlliagre
No script in /etc/init.d is directly executed, this directory is simply a convenient place to have real rc scripts linked to.
Reals rc scripts are in directories named rc2.d rc3.d etc, and starts with either an uppercase S or an uppercase K.

Well, there is no link to boot.cleanup in any of those floders. I assume that rc5.d is the folder for runlevel 5, which if I remember correctly, is the default one. So I guess that at boot, all these scripts are executed. How can I add a new script? Just make a link to one, and name it K22something, or S22something?


Quote:

Originally Posted by magnus.therning
If you reboot your machine regularly you might want to look into mounting a tmpfs filesystem on /tmp.

Hmm, I learned a bit about tmpfs, but I don't think this would be what I need for this. According to google, it's a file system where everything is loaded into RAM memory, if I understand correctly. I have 512Mb RAM and if I get something like a whole 700mb movie, as I have in /tmp loaded there, I don't think it will do any good.
But thanks, this is an interesting concept I haven't learned anything about so far. I could find other uses for a tmpfs... Off topic, does anyone have a good howto link?

jlliagre 09-07-2006 11:23 AM

Quote:

Originally Posted by Valkyrie_of_valhalla
How can I add a new script? Just make a link to one, and name it K22something, or S22something?

That's the idea.
Quote:

Hmm, I learned a bit about tmpfs, but I don't think this would be what I need for this. According to google, it's a file system where everything is loaded into RAM memory, if I understand correctly. I have 512Mb RAM and if I get something like a whole 700mb movie, as I have in /tmp loaded there, I don't think it will do any good.
But thanks, this is an interesting concept I haven't learned anything about so far. I could find other uses for a tmpfs...
tmpfs concept came from Solaris, which uses it by default for /tmp since ages. It's very convenient.
You can put a 700MB file in tmpfs with 512MB of RAM, as tmpfs is backed by virtual memory, but you won't have any improvement because the system would paginate quite a lot during the file creation.


All times are GMT -5. The time now is 04:53 AM.