Delete files with time stamp on Samba Server

Miguel Barbosa Gonçalves m at
Mon May 20 13:53:23 UTC 2013

On 20 May 2013 13:34, Leslie Jensen <leslie at> wrote:

> I have a remote Samba Server where Windows machines place backup files
> once a day. The format is
> backup_2013-05-03_13.45.44_.**zip
> Before the Windows client places the file it removes the file from the day
> before.
> In turn I do a backup of the backup files once every week(Friday) to
> another directory.
> This directory will eventually fill up and I need to make a check and
> remove the oldest file maybe once a week before the new file is copied, or
> put in other words I never want more than 4 files to be in this directory.
> My scripting skills are not at the level where I can figure this out, so
> I'll appreciate suggestions on how to solve this in the correct way.

Hi Leslie!

I believe this is what you need:

--- START ---


pg_dump -U gp > /backups/gp.`date +%Y%m%d-%H%M%S`.sql

for file in `ls -r /backups/gp.*`
       [ $N -gt $KEEP ] && rm -f $file
       N=`expr $N + 1`
--- END ---

I am using this to keep 5 backup files... Modify as needed.


More information about the freebsd-questions mailing list