Pergunta

I want to delete *.zip or *.log files but keep last created one(newest).

For example:

text-ids.zip(12.10.2013)
text-ids.zip(13.10.2013)
..
.
text-ids.zip(19.10.2013) <-- keep this one
Foi útil?

Solução

ls -ct *.zip | tail -n +2 | xargs rm
  • ls -ct show files, sorted by ctime
  • tail -n +2 remove first line
  • xargs rm call rm on the remaining
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top