LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-01-2015, 02:19 PM   #16
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050

This thread might have some useful information about mounting /tmp to tmpfs and other related issues to an over sized /tmp.

https://www.linuxquestions.org/quest...ng-4175543841/
 
Old 12-01-2015, 03:00 PM   #17
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,950

Rep: Reputation: Disabled
Quote:
Originally Posted by bassmadrigal View Post
While you're not likely to see real world speed improvements, using find's -delete option is more efficient than xargs or -exec. See this GNU page on deleting files for a more in-depth explanation on why -delete is the better option.

Code:
/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -delete
You could also add a check to only remove files that haven't been modified within the last week, which would minimize deleting and recreating common files.

Code:
/usr/bin/find /tmp -mindepth 1 -maxdepth 1 -mtime +7 -delete
-delete only seems to delete files, it doesn't seem to delete recursively leaving behind any directories.
 
Old 12-01-2015, 03:07 PM   #18
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
tmpwatch program can do cleaning of /tmp.
 
Old 12-01-2015, 03:27 PM   #19
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by orbea View Post
-delete only seems to delete files, it doesn't seem to delete recursively leaving behind any directories.
Looking into this more, it seems you're right. It looks like it will delete folders, but only if they're empty, so you'd need to run two find commands, one to delete the contents within a folder, and another to delete the remaining folders. Definitely not worth the possibly slightly better efficiency.

Disregard and carry on

(Although, the -mtime portion could still be handy, depending on what your intentions are.)
 
Old 12-01-2015, 05:54 PM   #20
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by bassmadrigal View Post
Looking into this more, it seems you're right. It looks like it will delete folders, but only if they're empty, ...
The find command will delete files and directories just fine provided that you haven't done something to prevent it from recursing into the directories and deleting the contents first. Using "-maxdepth" or tests that leave some files behind could prevent deleting a directory. Note the "-delete" implies "-depth", which tells find to process a directory's contents (i.e., delete them) before the directory itself.
 
1 members found this post helpful.
Old 12-01-2015, 06:28 PM   #21
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by rknichols View Post
The find command will delete files and directories just fine provided that you haven't done something to prevent it from recursing into the directories and deleting the contents first. Using "-maxdepth" or tests that leave some files behind could prevent deleting a directory. Note the "-delete" implies "-depth", which tells find to process a directory's contents (i.e., delete them) before the directory itself.
Ok, this is making much more sense now that I'm looking harder (I've always had a rough time with find). I had left the mindepth/maxdepth options in there, which are beneficial for xargs, but not when using -delete (at least the maxdepth since it won't allow any traversing within folders).

So, it seems like the following should work fine (I'll leave the mindepth on there, just in case).

Code:
/usr/bin/find /tmp -mindepth 1 -delete
I did a quick test in my home directory (I don't want to clear out my /tmp), and the -delete option worked fine.

Code:
jbhansen@craven-moorhead:~/tmp$ ls -laR
.:
total 12
drwxr-xr-x  3 jbhansen users 4096 Dec  1 19:33 ./
drwx--x--x 63 jbhansen users 4096 Dec  1 19:32 ../
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 .132
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 132
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 1323
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 13234
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 132345
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 1323456
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 13234567
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 132345678
-rw-r--r--  1 jbhansen users    0 Dec  1 19:32 1323456789
drwxr-xr-x  2 jbhansen users 4096 Dec  1 19:33 tmp2/

./tmp2:
total 8
drwxr-xr-x 2 jbhansen users 4096 Dec  1 19:33 ./
drwxr-xr-x 3 jbhansen users 4096 Dec  1 19:33 ../
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 .132
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 .1322
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 .13222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 .1322222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 .13222222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 .132222222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 1
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 13
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 132
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 1322
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 13222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 132222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 1322222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 13222222
-rw-r--r-- 1 jbhansen users    0 Dec  1 19:33 132222222
jbhansen@craven-moorhead:~/tmp$ cd   
jbhansen@craven-moorhead:~$ find ~/tmp/ -mindepth 1
/home/jbhansen/tmp/tmp2
/home/jbhansen/tmp/tmp2/.132222222
/home/jbhansen/tmp/tmp2/.1322222
/home/jbhansen/tmp/tmp2/132222222
/home/jbhansen/tmp/tmp2/13
/home/jbhansen/tmp/tmp2/132222
/home/jbhansen/tmp/tmp2/1322222
/home/jbhansen/tmp/tmp2/1
/home/jbhansen/tmp/tmp2/.1322
/home/jbhansen/tmp/tmp2/.13222
/home/jbhansen/tmp/tmp2/.13222222
/home/jbhansen/tmp/tmp2/132
/home/jbhansen/tmp/tmp2/.132
/home/jbhansen/tmp/tmp2/1322
/home/jbhansen/tmp/tmp2/13222
/home/jbhansen/tmp/tmp2/13222222
/home/jbhansen/tmp/1323456
/home/jbhansen/tmp/1323
/home/jbhansen/tmp/132345678
/home/jbhansen/tmp/132
/home/jbhansen/tmp/.132
/home/jbhansen/tmp/13234567
/home/jbhansen/tmp/13234
/home/jbhansen/tmp/1323456789
/home/jbhansen/tmp/132345
jbhansen@craven-moorhead:~$ find ~/tmp/ -mindepth 1 -delete
jbhansen@craven-moorhead:~$ find ~/tmp/ -mindepth 1
jbhansen@craven-moorhead:~$
 
Old 12-01-2015, 07:39 PM   #22
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by bassmadrigal View Post
So, it seems like the following should work fine (I'll leave the mindepth on there, just in case).

Code:
/usr/bin/find /tmp -mindepth 1 -delete
Yes, that will work just fine. And, you do want that "-mindepth 1". Without that, the /tmp directory itself would be deleted.
 
1 members found this post helpful.
Old 12-02-2015, 04:45 AM   #23
lensilvan
Member
 
Registered: Jun 2013
Distribution: Arch Linux, Mintppc, Slackware
Posts: 160

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bassmadrigal View Post
This does not occur with Slackware.

@lensilvan, you can safely delete all content in /tmp as root without worrying about screwing up your system. Although, you will likely lose any packages that have been created (most default to store the package in /tmp), so if you want to keep those, move them somewhere else. If you use SlackBuilds from slackbuilds.org, you can also look at clearing out just the /tmp/SBo folder and regaining all the space holding the compiled source of the program and the resulting package folder (used to create the actual Slackware package).
In fact, most files inside /tmp are slackbuild packages that were compiled and installed. However, should I assume that if I decide to clear /tmp, those packages will not be uninstalled since they are normally stored in /var/log/packages?
 
Old 12-02-2015, 06:38 AM   #24
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by lensilvan View Post
In fact, most files inside /tmp are slackbuild packages that were compiled and installed. However, should I assume that if I decide to clear /tmp, those packages will not be uninstalled since they are normally stored in /var/log/packages?
Nothing in /tmp should need to survive a reboot. The files written there when you run the slackbuilds are no exception.

Also, the files stored in /var/log/packages are information about packages (metadata to be pedantic) rather that the packages themselves. They mainly list the files installed when running installpkg for a given package, These installed files are those actually used when running the applications shipped in the package. Have a look at some of these files in /var/log/packages to get examples.

So, what you really need to keep are the files in /var/log/packages (they are needed by installpkg or removepkg), and the files installed by installpkg, listed in the former ones, used to run the applications.

Last edited by Didier Spaier; 12-02-2015 at 06:50 AM.
 
Old 12-02-2015, 07:42 AM   #25
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by lensilvan View Post
In fact, most files inside /tmp are slackbuild packages that were compiled and installed. However, should I assume that if I decide to clear /tmp, those packages will not be uninstalled since they are normally stored in /var/log/packages?
You likely have the packages, the source, and the folder used for the package preparation. With SBo, you'll end up with /tmp/SBo/$program-$version (the extracted source and compilation directory), /tmp/SBo/package-$program (the folder that everything is "installed" into so makepkg can generate the package), and /tmp/$program-$version-$arch-$build$tag.txz (the resulting package).

As Didier stated, none of that is needed once you install the program. You might want to hold onto the resulting packages, just in case you need to reinstall, but even if you remove the packages in /tmp, it won't prevent you from upgrading to newer versions or uninstalling those packages. All package information resides in /var/log/{packages|scripts}, so as long as that is not removed (which if you're just looking at cleaning up /tmp), your system should hum along perfectly.

Your computer should run completely fine if /tmp is empty on every boot.
 
Old 12-02-2015, 08:13 AM   #26
chemfire
Member
 
Registered: Sep 2012
Posts: 422

Rep: Reputation: Disabled
Its also worth pointing out on the SBo front that if you did build an SBo package and have installed it, you can recover the tgx or txz slackware package even if you don't keep it.

See the -copy and -warn switches on removepkg. The manual page will explain them.

So if you can't keep the packages around and do want to install them on another system or something without having to rebuild them (really why not just rebuild them) this is a way you can get them back.
 
Old 12-02-2015, 09:17 AM   #27
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
If you make the following changes to your system, you will not have a need to use the find command to delete files in /tmp.

Here are a few configurations changes for sbopkg (in /etc/sbopkg/sbopkg.conf) that I use to keep my machines clean:
  • Save compiled packages to a specified directory
Code:
export OUTPUT=${OUTPUT:-/home/youruser/Slackbuilds/Packages}
  • Clean up unpacked source files and package tree after a build
Code:
CLEANUP=${CLEANUP:-YES}
The first is useful so that you do not have to remember to copy built packages from /tmp to a directory to save them. Especially useful if you have /tmp mounted using tmpfs because all files in tmp will be wiped during poweroff/reboot. You can set this option to whichever directory you want.

The second is a little redundant if you have /tmp mounted on tmpfs. It will clean out stray files each time sbopkg is ran. I like this option because it keeps /tmp clean while my system is running. I often do not power down my machines (laptops) for days, weeks. I use pm-hibernate instead of shutting down most of the time. On a desktop or server this could mean months and years. Keeping things clean in /tmp is important to avoid running out of memory/disk space while a machine is being used.

As a reference, you can add the following to /etc/fstab to enable /tmp to be mounted using tmpfs. Where size=7G is equal to the desired size of /tmp in memory. If you have 512MB RAM, make it 500M. If you have 4GB of RAM, make it 3G. I have 8GB of RAM so I set it to 7G. Notice that G = GB and M = MB as a mount option.
Code:
tmp              /tmp             tmpfs       nodev,nosuid,size=7G         0   0

Last edited by mralk3; 12-02-2015 at 09:18 AM.
 
1 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My Debian system does not delete the content of /tmp automatically mr.simo Debian 5 12-14-2014 05:25 PM
[SOLVED] How to delete a directory in /tmp directory pradeepdee6 Linux - Newbie 7 12-14-2012 03:41 AM
Can't login, says tmp directory full but tmp file is empty! Could be linked to MySQL? bethanlowder Fedora 7 09-25-2009 07:17 AM
2 gigabyte /tmp directory..ok to delete contents pAn1k Linux - Newbie 3 09-02-2004 09:56 AM
Can I delete everything in the /tmp directory? BajaNick Linux - General 5 07-04-2004 01:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:41 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration