LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 09-04-2006, 03:45 PM   #1
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Rep: Reputation: 30
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.

Last edited by Valkyrie_of_valhalla; 09-04-2006 at 03:48 PM.
 
Old 09-04-2006, 04:11 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
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
 
Old 09-04-2006, 04:53 PM   #3
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Original Poster
Rep: Reputation: 30
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?
 
Old 09-04-2006, 07:04 PM   #4
TSquaredF
Member
 
Registered: Dec 2005
Location: "The South Coast of Texas"
Distribution: Slackware64-current
Posts: 488
Blog Entries: 1

Rep: Reputation: 55
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
 
Old 09-05-2006, 11:27 AM   #5
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Original Poster
Rep: Reputation: 30
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.
 
Old 09-05-2006, 11:56 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
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.
 
Old 09-05-2006, 03:54 PM   #7
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Original Poster
Rep: Reputation: 30
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.
 
Old 09-05-2006, 05:53 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
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
 
Old 09-06-2006, 11:23 AM   #9
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Original Poster
Rep: Reputation: 30
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?
 
Old 09-06-2006, 12:20 PM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
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.
 
Old 09-07-2006, 02:41 AM   #11
magnus.therning
LQ Newbie
 
Registered: Jul 2006
Location: Cambridge
Distribution: Debian
Posts: 20

Rep: Reputation: 0
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.
 
Old 09-07-2006, 03:40 AM   #12
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Rep: Reputation: 30
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 *
 
Old 09-07-2006, 04:51 AM   #13
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
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 ...

Last edited by jlliagre; 09-07-2006 at 11:25 AM.
 
Old 09-07-2006, 11:04 AM   #14
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Original Poster
Rep: Reputation: 30
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?
 
Old 09-07-2006, 11:23 AM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting files deleted on /tmp ines Linux - General 13 01-28-2005 03:35 AM
/tmp files Risc91 AIX 4 01-18-2005 02:06 PM
Deleting tmp files satimis Fedora 6 10-31-2004 08:59 PM
Numerous scb_*.tmp files in /tmp dburk Programming 3 08-18-2003 04:28 PM
removing files in /tmp sakeeb Linux - General 4 06-09-2002 12:09 AM


All times are GMT -5. The time now is 11:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration