Jump to content

[SOLVED] Erase oldest file?


rantsh

Recommended Posts

I have a crontab that creates a tar file with a backup of my site, now, I'm required to erase the oldest file after I generate a new backup... anyone know how can I determine the oldest file in a folder???

All my files are named something like

[code]
Backup_ddmmYYYY_tar.gz
[/code]

Thanks for any help you may provide
Link to comment
Share on other sites

xargs basically takes standard input and appends it to another commands arguments. So yeah... the command you have does exactly what you want.

The first par....

[code]
ls -t -r -1 /var/log/kdm.log.*
[/code]

displays all files within /var/log beginning with kdm.log sorted by timestamp, oldest to newest in a single colum. It then pipes the output to the next part.....

[code]
head --lines 1
[/code]

which trims the output down to one file (the oldest one), then pipes it to xargs which appends the filename to the arguments of rm and executes it.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.