Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: /tmp & /var/tmp - safe to remove?

  1. #1
    Join Date
    Apr 2018
    Location
    U.S Midwest just West of the Mississippi River
    Posts
    641

    Default /tmp & /var/tmp - safe to remove?

    I thought these were cleaned out during boot. But mine are growing, granted not exponentially every day, but still things are there from 1st install date.

    My question is can I remove content from those two directories?

    I understand there are tweaks that can be made in a sys config file to do it during boot, but so far they have gone over my balding old head.
    I even tried finding out how in the SDB documents but didn’t find it(yet).
    HP Compaq desktop Leap15.1 Win10, Win7
    Toshiba laptops Leap15.1 & Win10, HP AiO Win10.
    I can now print with openSuSe Leap! Can Scan now, could be better!!
    I can backup my iPod and iPad with Windows, can't with Linux.(Will get there someday!)

  2. #2
    Join Date
    Jun 2008
    Location
    Auckland, NZ
    Posts
    21,220
    Blog Entries
    1

    Default Re: /tmp & /var/tmp - safe to remove?

    One option to make sure /tmp files are killed on shutdown/reboot is to set up /tmp using tmpfs. Set up an /etc/fstab entry
    Code:
    tmpfs   /tmp         tmpfs   rw,nodev,nosuid,size=2G          0  0
    https://wiki.archlinux.org/index.php/Tmpfs
    or the systemd way
    Code:
    ln -s  /usr/share/systemd/tmp.mount /etc/systemd/system/tmp.mount
    It will take effect at next boot. You can remove the old disk /tmp as Neil describes well here...
    https://nwrickert2.wordpress.com/201.../cleaning-tmp/
    Last edited by deano_ferrari; 20-Feb-2019 at 13:43.
    openSUSE Leap 15.1; KDE Plasma 5

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,206

    Default Re: /tmp & /var/tmp - safe to remove?

    Better do not remove them. As you saw, they are used. Those programs will probably break when they can not use them.

    For cleaning /tmp and /var/tmp at boot:


    When there is not already a file /etc/tmpfiles.d/tmp.conf create it as a copy


    Code:
    cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf

    Then change the lines
    Code:
    # Clear tmp directories separately, to make them easier to override
    # SUSE policy: we don't clean those directories
    d /tmp 1777 root root -
    d /var/tmp 1777 root root -

    into
    Code:
    # Clear tmp directories separately, to make them easier to override
    # My policy: empty /tmp en /var/tmp on boot.
    D! /tmp 1777 root root 1d
    D! /var/tmp 1777 root root 1d
    See
    Code:
    man 5 tmpfiles.d
    Henk van Velden

  4. #4
    Join Date
    Jan 2017
    Location
    Nürnberg, Germany
    Posts
    265

    Default Re: /tmp & /var/tmp - safe to remove?

    I find it instructive to have lsof list all open files on occasion, especially under /tmp and /home:
    Code:
    lsof -nP | grep tmp
    lsof -nP | grep home
    Usually on my system, it’s the web browser keeping hundreds of files opened in many subfolders, also the desktop environment (SeaMonkey and KDE/Plasma5 in my case).
    It lets me gauge roughly whether maybe my SSDs are getting stressed a bit too much, if tmpfs-mounting might be in order, and how all-in-all-blazingly fast our Linux rigs have become.

  5. #5
    Join Date
    Apr 2018
    Location
    U.S Midwest just West of the Mississippi River
    Posts
    641

    Default Re: /tmp & /var/tmp - safe to remove?

    Quote Originally Posted by hcvv View Post
    Better do not remove them. As you saw, they are used. Those programs will probably break when they can not use them.

    For cleaning /tmp and /var/tmp at boot:

    When there is not already a file /etc/tmpfiles.d/tmp.conf create it as a copy

    Code:
    cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf
    Did this^^^ /etc/tmpfiles.d/ was empty
    Then I change the lines in copied file

    Quote Originally Posted by hcvv View Post
    Code:
    # Clear tmp directories separately, to make them easier to override
    # SUSE policy: we don't clean those directories
    d /tmp 1777 root root -
    d /var/tmp 1777 root root -
    [U][B]I changed the lines in the /etc/tmpfiles.d/tmp.conf
    However, the 'd's in your lines were 'q's in my file.See next code lines.
    Code:
    # Clear tmp directories separately, to make them easier to override
    # SUSE policy: we don't clean those directories
    q /tmp 1777 root root -
    q /var/tmp 1777 root root -
    Quote Originally Posted by hcvv View Post
    Code:
    into
    # Clear tmp directories separately, to make them easier to override
    # My policy: empty /tmp en /var/tmp on boot.
    D! /tmp 1777 root root 1d
    D! /var/tmp 1777 root root 1d
    See
    Code:
    man 5 tmpfiles.d
    [/QUOTE]
    Yeah that is part of what went completely over my head.
    But after all is said and done, /tmp was cleared of things oldr that 1 day.
    But> /var/tmp was not cleared of anything! it has things going back to 11/10/2108(install date) most of which are named like this
    Code:
    zypp.0G3XN9
    (221 of them), and one of this
    Code:
    TmpDir.shMuXt
    HP Compaq desktop Leap15.1 Win10, Win7
    Toshiba laptops Leap15.1 & Win10, HP AiO Win10.
    I can now print with openSuSe Leap! Can Scan now, could be better!!
    I can backup my iPod and iPad with Windows, can't with Linux.(Will get there someday!)

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,206

    Default Re: /tmp & /var/tmp - safe to remove?

    As the man page says, q is used for sub-volumes when using btrfs. When not. it is equal to d.
    This q seems to be relative new. It is not in the 13.1 man page (which I happen to have on-line), but it is in 15.0. So somewhere in between ....

    Maybe the not working on /var/tmp has something to do with btrfs, I do not know. But all those old files can of course be removed manualy when they use a considarable amount of space.
    Henk van Velden

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,206

    Default Re: /tmp & /var/tmp - safe to remove?

    Re-reading the thread, I see that I warned against removing /tmp and /var/tmp. That was not what you suggested, you asked if you could remove the contents of those without fear for problems. And you can. Specialy those (very) old ones, that will not be open anymore for amy process because the processes wil have stoppen long ago due to a shutdown. Only take care about programs that are created/used since last reboot..
    Henk van Velden

  8. #8
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    13,589
    Blog Entries
    3

    Default Re: /tmp & /var/tmp - safe to remove?

    I'll note that I am using:
    Code:
    D /tmp 1777 root root 7d
    q /var/tmp 1777 root root 14d
    for those two lines.

    "/tmp" only has files since the last boot. But my entry for "/var/tmp" doesn't clean out everything. There are two older directories -- presumably because they are still being accessed. It is clean enough for me.
    openSUSE Leap 15.2 Beta; KDE Plasma 5;

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,206

    Default Re: /tmp & /var/tmp - safe to remove?

    As a side note.

    Using D! instead of D makes sure that cleaning only will take place at boot. Which might be important when using 1d, using 7d might assure that no active files are deleted.

    All this depends of course on how often a boot is done. When the system is "never" booted (meaning several days, maybe weeks between boots), cleaning on boot only may not be what you want. and thus the 7d and no ! is probably a good solution.

    It is of course not for nothing that I point to the man page. Everybody should invent his own best solution depending on his computer's way of life.
    Henk van Velden

  10. #10
    Join Date
    Apr 2018
    Location
    U.S Midwest just West of the Mississippi River
    Posts
    641

    Default Re: /tmp & /var/tmp - safe to remove?

    Quote Originally Posted by hcvv View Post
    Maybe the not working on /var/tmp has something to do with btrfs, I do not know. But all those old files can of course be removed manualy when they use a considarable amount of space.
    Nothing formatted with btrfs. Does openSuSe use it regardless of how partitions are formatted?
    HP Compaq desktop Leap15.1 Win10, Win7
    Toshiba laptops Leap15.1 & Win10, HP AiO Win10.
    I can now print with openSuSe Leap! Can Scan now, could be better!!
    I can backup my iPod and iPad with Windows, can't with Linux.(Will get there someday!)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •