purge unused layers

 From:  okapi
3774.1 
is there a command for purging unused layers, or a script that can do that?
Thanks,