OPNsense Forum

English Forums => General Discussion => Topic started by: vikozo on May 05, 2022, 04:41:56 PM

Title: delet older files
Post by: vikozo on May 05, 2022, 04:41:56 PM
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
Title: Re: delet older files
Post by: zerwes on May 05, 2022, 04:45:27 PM
man find
Title: Re: delet older files
Post by: zerwes on May 05, 2022, 04:52:35 PM
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)