SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
-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.)
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.
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:~$
@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?
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.