FG

What's wrong with my bash script to keep last x files and delete the rest?

Fresh3 days ago
Mar 15, 202617655 views
Confidence Score0%
0%

Problem

I have this bash script which nicely backs up my database on a cron schedule: Problem with this is that it will keep dumping the backups in the folder and not clean up old files. This is where the variable comes in. Whatever number this is set to thats the amount of backups I want to keep. All back…

Error Output

#!/bin/sh

PT_MYSQLDUMPPATH=/usr/bin
PT_HOMEPATH=/home/philosop
PT_TOOLPATH=$PT_HOMEPATH/philosophy-tools
PT_MYSQLBACKUPPATH=$PT_TOOLPATH/mysql-backu…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: What's wrong with my bash script to keep last x files and delete the rest?

Low Risk

You could try this one: will list all files in reverse order, one file per line. filters the first $number-1 files of the list out (resp. displays all files beginning from $number till the last one). will execute with all file names from standard in…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment