I have a directory of files with similar names, but with incrementing digits as a suffix. I want to remove the lower suffixed files and only keep the files with the highest suffix. Below is an example file listing:
1k_02.txt
1k_03.txt
1l_02.txt
1l_03.txt
1l_04.txt
2a_05.txt
2a_06.txt
4c_03.txt
4c_04.txt
The above list needs to be reduced to the files below:
1k_03.txt
1l_04.txt
2a_06.txt
4c_04.txt
I don't even know where to start with this, but if possible I would like a single bash command.
1k_03.txt
should be kept but4c_03.txt
should be removed? – RomanPerekhrest Nov 29 '17 at 20:07zsh -c ‘rm ....’
– Jeff Schaller Nov 29 '17 at 20:09