What is the best way to remove all the files in the current directory with some prefix, except the file with this prefix but having the largest size among all the files with this prefix?
(In the case when the largest one is not unique, just randomly keep one of them and remove the others.)
For example, the current directory contains the following files:
-rw-rw---- 1 user user 3468 Jan 01 00:00 filea
-rw-rw---- 1 user user 3434 Jan 01 00:00 pre_0
-rw-rw-r-- 1 user user 9769 Jan 01 00:00 fileb
-rw-rw-r-- 1 user user 1950 Jan 01 00:00 filec
-rw-rw-r-- 1 user user 8654 Jan 01 00:00 pre_1
-rw-rw---- 1 user user 6508 Jan 01 00:00 pre_2
After running the command or the script to remove all the files with prefix "pre_" except the largest one, the current directory should be listed as:
-rw-rw---- 1 user user 3468 Jan 01 00:00 filea
-rw-rw-r-- 1 user user 9769 Jan 01 00:00 fileb
-rw-rw-r-- 1 user user 1950 Jan 01 00:00 filec
-rw-rw-r-- 1 user user 8654 Jan 01 00:00 pre_1