We have a custom Yum repo that our developers upload builds to.

The problem is that after some time it becomes cluttered with old versions.

Removing the old versions manually is quite annoying, so before we try to automate it ourselves, I wonder if there any script that would clean old RPM's based on version (preferred) or time of upload.

Best would be if we could specify to simple save X last versions, and erase anything else. Then we could cron it and just let it run daily.

Thanks for any idea.

  • If there's not a script, there should be. We wrote one for our own use at our company, but I will see about releasing this into the wild if possible.
    – Andrew M.
    Nov 4, 2011 at 21:14
  • Great - I will appreciate if it can be open-sourced. Posting on github would be a great odea.
    – SyRenity
    Nov 6, 2011 at 10:02

4 Answers 4


The "simple" way is to just dump everything in a directory and run:

rm $(repomanage --keep=2 --old /path/to/repo)
createrepo /path/to/repo

...the more complicated way is to setup koji/etc. to do your builds and create the repos.

  • Cool - that exactly what I needed.
    – SyRenity
    Sep 26, 2012 at 17:57
  • great stuff, wasn't aware of this one
    – dyasny
    Oct 27, 2014 at 19:56
  • Technically, you should use it together with xargs instead, because otherwise you might get rm: missing operand (if there are no old RPMs to remove). So: repomanage --keep=2 --old /path/to/repo | xargs rm -f Mar 16, 2019 at 9:27
  • The reason to use xargs is because rm $(repomanage --keep=2 --old /path/to/repo) could easily exceed the maximum command length. xargs will take care of a huge list of arguments. See:offbytwo.com/2011/06/26/things-you-didnt-know-about-xargs.html
    – shrewmouse
    Aug 22, 2019 at 16:11

Check out the "repomanage" utility from the yum-utils RPM. It does exactly what you're looking for.

[root ~]# repomanage --help
  repomanage: manage a directory of rpm packages. returns lists of newest
            or oldest packages in a directory for easy piping to xargs
            or similar programs.
  repomanage [--old] [--new] path.

    -h, --help            show this help message and exit
    -o, --old             print the older packages
    -n, --new             print the newest packages
    -s, --space           space separated output, not newline
    -k KEEP, --keep=KEEP  newest N packages to keep - defaults to 1
    -c, --nocheck         do not check package payload signatures/digests
[root ~]#

I would leverage the versioning or labeling system you use to identify builds. You could also identify packages by date with a script running on the server hosting the repository.

  • You mean by checking the version in file names? This is my line of thought as well, but would be nice to have an automated script for this.
    – SyRenity
    Nov 6, 2011 at 10:03
  • 1
    Also remember that the filename is not necessarily indicative of the version. I.e., I can rename an RPM to anything I want; yum will use the metadata of the RPM instead.
    – Andrew M.
    Nov 6, 2011 at 15:26

If the uploads happen everyday, why not consider deleting the old files which are older beyond say certain number of days(in terms of their access/modification times)? Find and just delete them. If you could have your developers upload builds such that they put the name of the current month into the filename when uploading, it would make sense from the filename directly that the file was uploaded in so called month'year and it makes sense to delete just by the basis of looking at the filename. It would make easy for your script automation to just consider removing those files or just keep those files which match previous month and current month. Just a thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.