Can one automatically delete older thumbnails when that folder got too large?

Technical issues/questions of an intermediate or advanced nature.
User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#1 by Rava » 29 Mar 2023, 05:36

I could not create the most recent Palemoon module because to extract the xz-tarball there needs some free space in /tmp

But currently my / is full:

Code: Select all

guest@porteus:~/.cache$ df -Tm /
Filesystem     Type 1M-blocks  Used Available Use% Mounted on
aufs           aufs       388   388         0 100% /
The reason, mainly: Thumbnails in /home/guest :

Code: Select all

guest@porteus:~/.cache$ du -m thumbnails/
1	thumbnails/fail/gnome-thumbnail-factory
1	thumbnails/fail
91	thumbnails/large
148	thumbnails/normal
239	thumbnails/
239 MB in thumbnails is overkill in my book. :wall:

Therefore my question: is there a background way that not uses much system resources that will delete older thumbnails?

E.g. run it once an hour to keep the thumbnails/ folder in between a given size limit (e.g. not larger than 100 MB) by removing the oldest thumbnails.

The cron entry itself is not that much of a challenge.
All files and folders thumbnails/fail should be deleted regardless of age.
Then the thumbnails/large should be deleted, then the oldest from thumbnails/normal until the used space is once more below the threshold (e.g. 100MB)

I do not want to code that. Image

But I am sure somewhere in the vast space of the Linuxverse there already exists the solution for doing just that.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Can one automatically delete older thumbnails when that folder got too large?

Post#2 by Ed_P » 29 Mar 2023, 05:44

I would delete all of them. The current ones will be rebuilt as you use the system.
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#3 by Rava » 29 Mar 2023, 06:24

Ed_P wrote:
29 Mar 2023, 05:44
I would delete all of them. The current ones will be rebuilt as you use the system.
That's what I do, but I would like to have the system do it by itself when the folder got too large.
A PC system should be able to do such tasks on its own. :D
Cheers!
Yours Rava

donald
Full of knowledge
Full of knowledge
Posts: 2063
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#4 by donald » 29 Mar 2023, 08:41

maybe delete only those files which have not been accessed for a given periode of time.
...via cron or script.

Code: Select all

find ~/.cache/thumbnails/{large,normal}/ -type f -atime +7 -delete

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#5 by Rava » 29 Mar 2023, 09:25

Hi donald, wie geht's?
donald wrote:
29 Mar 2023, 08:41
maybe delete only those files which have not been accessed for a given periode of time.
...via cron or script.

Code: Select all

find ~/.cache/thumbnails/{large,normal}/ -type f -atime +7 -delete
That works.

But cron is run by root or not?
Therefore it must be

Code: Select all

find /home/guest/.cache/thumbnails/{large,normal}/ -type f -atime +7 -delete
since I hardly ever use the GUI file browser to go anywhere, as root I mostly use a terminal.
Cheers!
Yours Rava

donald
Full of knowledge
Full of knowledge
Posts: 2063
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#6 by donald » 29 Mar 2023, 23:19

Rava wrote:
29 Mar 2023, 09:25
Hi donald, wie geht's?
passt scho.. :)


Rava wrote:
29 Mar 2023, 09:25
But cron is run by root or not?
Every user can use cron if (s)he has a crontab.
seems porteus has a crontab for root but not for guest.
as guest check with crontab -l if you have one.
If not, you can create a empty one with crontab -e
Be aware that you will be in trouble if you don't know how to
use / exit vim/vi.

However, a cron job for that simple task (to delete thumbnails) would be overkill - imo.
Rava wrote:
29 Mar 2023, 09:25
since I hardly ever use the GUI file browser.........I mostly use a terminal.
I would use an alias in .bashrc to run the (delete old thumbs) command when needed.

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#7 by Rava » 30 Mar 2023, 03:23

donald wrote:
29 Mar 2023, 23:19
However, a cron job for that simple task (to delete thumbnails) would be overkill - imo.
But i want it to be automated, so using cron to say, check twice a day and do a delete - but with few that 7 days ago, maybe one day, woulddo e trick and not does that have such a burden on the system, yes?

That would be this, yes?

Code: Select all

find /home/guest/.cache/thumbnails/{large,normal}/ -type f -atime +1 -delete
find /home/guest/.cache/thumbnails/fail/ -type f -delete
Cheers!
Yours Rava

donald
Full of knowledge
Full of knowledge
Posts: 2063
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#8 by donald » 30 Mar 2023, 05:17

Rava wrote:
30 Mar 2023, 03:23
But i want it to be automated, so using cron to say....
Check what is in the root crontab

Code: Select all

root@porteus:/# crontab -l
mine says that whatever script is in /etc/cron.daily/
runs at 19:30 every day.
If once a day is sufficient, put the "thumbs-delete" script in cron.daily.
Rava wrote:
30 Mar 2023, 03:23
That would be this, yes?

Code: Select all

find /home/guest/.cache/thumbnails/{large,normal}/ -type f -atime +1 -delete
find /home/guest/.cache/thumbnails/fail/ -type f -delete
should work - if not, add the path to the find binary in the script.
/usr/bin/find /home/guest/.cache/thumb....

I do not have a 'fail' folder (older porteus vesion), why not add it {large,normal,fail}?

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Can one automatically delete older thumbnails when that folder got too large?

Post#9 by Rava » 30 Mar 2023, 14:53

donald wrote:
30 Mar 2023, 05:17
I do not have a 'fail' folder (older porteus vesion), why not add it {large,normal,fail}?
I also do usually not have a fail folder. But I put it in extra since I think all fail thumbnails should be purged regardless of age since they are of no real use (whatever it means when a thumbnail is saved in the fail folder, I do not know)
But sure, having only one find line is more efficient.

Code: Select all

root@porteus:~# cat /etc/cron.daily/thumbs-delete 
#!/bin/sh
/usr/bin/find /home/guest/.cache/thumbnails/{large,normal,fail}/ -type f -atime +1 -delete
I made it the same owner and permissions as the existing files, that is:

Code: Select all

Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Cheers!
Yours Rava

Post Reply