Reputation: 93
This works to delete files older then 14 days
find /path/to/share -type f -iname "*.*" -mtime +14 -exec rm -f {} \;
I need to modify, leave only 10 latest files, no matters how old are they
Upvotes: 3
Views: 2727
Reputation: 803
find /path/to/share -type f -iname "*.*" | sort | sed -n -e :a -e '1,10!{P;N;D;};N;ba' | xargs rm
PS If you not need sort, remove it.
Upvotes: 1