ls -ct *.zip | tail -n +2 | xargs rm
ls -ct
show files, sorted by ctimetail -n +2
remove first linexargs rm
callrm
on the remaining
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
Solução
ls -ct *.zip | tail -n +2 | xargs rm
ls -ct
show files, sorted by ctimetail -n +2
remove first linexargs rm
call rm
on the remaining