Re: Bash script question
On Thursday 07 December 2006 11:16, Nate Bargmann wrote:
> Since there is a lot of knowledge on this list, I thought I'd aske
> This may be trivial, but I'm not even sure how to search for what I
> want to do.
> I have a directory of files that are created daily using
> filename-`date +%Y%m%d`.tar.gz so I have a directory with files whose
> names advance from filename-20061201.tar.gz to filename-20061202.tar.gz
> to filename-20061203.tar.gz and so on. Based on the date in the
> filename, I would like to delete any than are X days older than today's
> date. So, I'm not interested in the actual created/modified date, just
> the numeric string in the name.
This will require some debugging on your part, but hopefully this will be
for file_name in *tar.gz;
file_to_remove_date=echo $file_name | tr -d [:alpha:] | tr -d [=-=];
if test $file_to_remove_date -le $old_date;
echo "rm $file_name";
There are certainly better ways to do this. You can do a man tr to see what
the above is doing.