delet older files

Started by vikozo, May 05, 2022, 04:41:56 PM

Previous topic - Next topic
Hello
Nothing to do with OpnSense! But maybe some nerds could help

i have a vm with jellyfin watching movies i have e directory filling up with some *.ts files.
until the older are deleted by the system or the disk run full.

is there a command to
find in a directory the oldest not used file and only keep the newest 10 or 20 files?

have a nice day
vinc
apu2c4 / wle200nx / 240 Disk --> Firewall | FW-03
---
OPNsense 22.1.6-amd64
FreeBSD 13.0-STABLE
OpenSSL 1.1.1n 15 Mar 2022


OK, maybe a post should consist of more then 8 characters :-)

delete all files in DIR (and subdirs!) matching '*.ts' older then 30 days
find /my/directory/to/clean/up/ -type f -name '*.ts' -mtime 30 -exec rm -v {} \;
if you just want to keep the newest 20 and all are in one directory you can even use ls
cd /my/directory/to/clean/up/; rm $(ls -1t *.ts | head -20)