LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Command to clean tmp at shutdown (http://www.linuxquestions.org/questions/slackware-14/command-to-clean-tmp-at-shutdown-4175470934/)

rng 07-25-2013 08:16 PM

Command to clean tmp at shutdown
 
According to http://docs.slackware.com/howtos:gen...ree_your_space, following command should be put in /etc/rc.d/rc.local_shutdown :
Code:

/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -print0 | xargs -0r /bin/rm -rf
Why not put a simple command:
Code:

rm -rf /tmp/*

cisneros 07-25-2013 08:40 PM

so if the script fails the deleting process does not stop, because every file triggers a different rm process, i guess...

rkelsen 07-25-2013 09:01 PM

tmpfs is a better solution...

guanx 07-25-2013 09:09 PM

Because * does not expand hidden files by default (but can be changed).
BTW, tmpfs is much slower than ext3/4, etc. when it makes extensive use of swap.

Paulo2 07-25-2013 09:20 PM

Quote:

Originally Posted by guanx (Post 4996906)
Because * does not expand hidden files by default (but can be changed).
BTW, tmpfs is much slower than ext3/4, etc. when it makes extensive use of swap.

That's right, I use "ls -A" to list hidden files and a loop to clean /tmp




Quote:

Originally Posted by cisneros
so if the script fails the deleting process does not stop, because every file triggers a different rm process, i guess...

I didn't know that. But I didn't note any delay at shutdown by cleaning /tmp

rkelsen 07-25-2013 10:13 PM

Quote:

Originally Posted by guanx (Post 4996906)
BTW, tmpfs is much slower than ext3/4, etc. when it makes extensive use of swap.

Yes, that makes sense... But surely, modern desktop machines with 6 to 8 gigs of memory wouldn't really need to use swap that much, would they?

In the ~15 years I've been using Linux as my main desktop OS, I almost cannot recall ever seeing it actually use swap... maybe back when my machine had 256Mb RAM and I was running StarOffice on KDE, but certainly not much at all in recent years.

Martinus2u 07-26-2013 12:32 AM

Quote:

Originally Posted by rkelsen (Post 4996945)
Yes, that makes sense... But surely, modern desktop machines with 6 to 8 gigs of memory wouldn't really need to use swap that much, would they?

In the ~15 years I've been using Linux as my main desktop OS, I almost cannot recall ever seeing it actually use swap... maybe back when my machine had 256Mb RAM and I was running StarOffice on KDE, but certainly not much at all in recent years.

totally correct. it doesn't make sense to set up a swap device at all on most machines these days. Unfortunately the internet is still full of braindonated guides advising you to set up swap, sometimes even at twice the size of RAM. But technically guanx is right: it is madness to trade tmpfs for swap. Anything that might trigger the use of swap and thus thrashing should be avoided.

rg3 07-26-2013 02:36 AM

Quote:

Originally Posted by Paulo2 (Post 4996909)
That's right, I use "ls -A" to list hidden files and a loop to clean /tmp

As a general best practice, avoid parsing the output of ls if you can. Files containing weird characters can be a problem. The find solution provided in the OP post is a bit more verbose, but totally secure in that regard, using null characters as terminators (a null character can never appear in the middle of a name in Linux).

guanx 07-26-2013 03:08 AM

I think find/xargs does not introduce more security than the dotglob shopt but find/xargs is more portable and also works when there are too many files.

guanx 07-26-2013 03:18 AM

Quote:

Originally Posted by rkelsen (Post 4996945)
Yes, that makes sense... But surely, modern desktop machines with 6 to 8 gigs of memory wouldn't really need to use swap that much, would they?

In the ~15 years I've been using Linux as my main desktop OS, I almost cannot recall ever seeing it actually use swap... maybe back when my machine had 256Mb RAM and I was running StarOffice on KDE, but certainly not much at all in recent years.

Thanks for sharing your experience. So you rarely used swap since 1998? I believe you because Bill Gates used to say 640kB was enough, and in 1998 you could get 64MB for a PC, nearly 100 times more than enough.

However, 8 GB is not large enough for my temp files. I also use suspend to disk more than once per day. I think I'm far from getting rid of swap.

Mark Pettit 07-26-2013 03:31 AM

Many years ago the ratio between memory speed and disk speed (latency + transfer rate) was low, and memory was VERY expensive - thus virtual memory (page swapped to disk) was plausible. However, since then, memory has become both fantastically cheap and fast, while disk speed has not even come close to matching those advances. 30 years back I was dealing with mainframe disks of 200 MegaBytes in size (quite large then) which had latencies of about 15 millisecs. Now disks are down to maybe 5 millisecs. Transfer rates are better, but maybe 30 to 100 times. Memory is millions of times larger and almost billions of times cheaper. So,, if your system starts swapping in any fashion, it will appear that your machine is driving through treacle. While it's true that SSD's are rewriting those rules, the issues they still have with write-cycles is a problem. Conclusion - don't use memory for temp files : they will increase the likelihood that you will use swap and die.

ruario 07-26-2013 07:12 AM

Quote:

Originally Posted by rng (Post 4996864)
Code:

/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -print0 | xargs -0r /bin/rm -rf

Why not:

Code:

/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -exec /bin/rm -rf {} \;
It seems like the use of xargs is undeeded.

fl0 07-26-2013 07:26 AM

Quote:

Originally Posted by ruario (Post 4997160)
Why not:

Code:

/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -exec /bin/rm -rf {} \;
It seems like the use of xargs is undeeded.

or the same as xargs, but builtin
Code:

/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -exec /bin/rm -rf {} +;
regards fl0

rkelsen 07-26-2013 08:56 AM

Quote:

Originally Posted by guanx (Post 4997075)
However, 8 GB is not large enough for my temp files.

!

what are you possibly doing with your machine to make this true?

to everyone who is saying that tmpfs will cause your machine to swap: you can easily limit the size of a tmpfs. mine is limited to 1 gig, and I've never come anywhere near filling it. this is on a machine with 4gigs ram, and I haven't yet seen any swapping... or at least I haven't noticed it.

Richard Cranium 07-26-2013 10:02 AM

Quote:

Originally Posted by rkelsen (Post 4997226)
!

what are you possibly doing with your machine to make this true?

Well, perhaps he's encoding DVD images in a way that uses a couple of intermediate images.


All times are GMT -5. The time now is 05:06 AM.