rantsh Posted January 30, 2007 Share Posted January 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/ Share on other sites More sharing options...
rantsh Posted January 30, 2007 Author Share Posted January 30, 2007 I found this code in another forum[code]ls -t -r -1 /var/log/kdm.log.* | head --lines 1 | xargs rm[/code]and it seems to work BUT I'm unsure because I've never used xargs... anyone understand what it really does?thx Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-172939 Share on other sites More sharing options...
trq Posted January 30, 2007 Share Posted January 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-173084 Share on other sites More sharing options...
rantsh Posted February 2, 2007 Author Share Posted February 2, 2007 Thanks, it's been solved Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-175297 Share on other sites More sharing options...
neylitalo Posted February 2, 2007 Share Posted February 2, 2007 Please don't title your threads "HELP PLEASE". It's annoying when stuff is in all caps and it's a generic title that tells us nothing. Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-175412 Share on other sites More sharing options...
rantsh Posted February 2, 2007 Author Share Posted February 2, 2007 Sure, I'm sorry... won't happen again... I was wondering though how do you put the checkmark to a solved topic? Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-175499 Share on other sites More sharing options...
neylitalo Posted February 2, 2007 Share Posted February 2, 2007 There should be a little link at the bottom left saying "Topic Solved" - click that. Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-175512 Share on other sites More sharing options...
rantsh Posted February 3, 2007 Author Share Posted February 3, 2007 I've been looking for that link in some of my other topics so I could mark them... but either there's no link or I'm going blind!!!!, please give me a hint of around where it is... Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-175878 Share on other sites More sharing options...
neylitalo Posted February 3, 2007 Share Posted February 3, 2007 I've attached a screenshot of where it is on my screen - the link says "Topic not solved" because it's currently marked solved. Quote Link to comment https://forums.phpfreaks.com/topic/36363-solved-erase-oldest-file/#findComment-176323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.