Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easily selectively destroy temp files #2

Open
hopeseekr opened this issue Sep 20, 2020 · 1 comment
Open

Easily selectively destroy temp files #2

hopeseekr opened this issue Sep 20, 2020 · 1 comment
Labels

Comments

@hopeseekr
Copy link

hopeseekr commented Sep 20, 2020

The Problem

Linux stores lots of cache files I don't give a damn about that take up many GBs of space. Today, I just reclaimed over 23 GB of space from just deleting one user's ~/.cache/ directories.

The issue arises that rm is not very safe and is very unwieldly when it comes to excluding patterns of files/directories I want to keep, while also having various race conditions of not deleting files added once the process starts.

To get past this, I wanted to use rsync, but it has no ability to JUST delete files. You have to copy them somewhere, first.

The Solution

Enter nullfsvfs:

This is what I now have in my /etc/cron.daily/clean-cache:

#!/bin/bash

rsync -rv --remove-source-files --exclude={composer,spotify,skype,thumbnails,vim} /home/*/.cache/ /run/media/sinkhole/
for user in `ls /home`; do
    find /home/$user/.cache/ -type d -empty -delete
done

Update: I have officially released this as part of my BashScripts collection:

https://github.com/hopeseekr/BashScripts/blob/master/cron.daily/00_clear-cache

image

@abbbi abbbi added the Usecase label Sep 20, 2020
@abbbi abbbi changed the title Please add my usecase: Easily selectively destroy temp files Easily selectively destroy temp files Sep 20, 2020
@abbbi abbbi pinned this issue Sep 20, 2020
@abbbi abbbi unpinned this issue Sep 20, 2020
@hopeseekr
Copy link
Author

Hey!!! I LOVE how you slapped a label on this and linked to it in the README (via 60b74d9)!!

I'm going to use this trick myself and teach all of my future teammates!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants