Answer the question
In order to leave comments, you need to log in
How to write a bash script to compare and select filenames containing a number in the name?
I'm looking for information or ready-made solutions.
Supposedly there are several files (one, two or more) named:
Answer the question
In order to leave comments, you need to log in
VARIABLE=$(ls -v1 *.jar |tail -n1)
find . -name "*.jar" ! -name "$VARIABLE" -delete
Since the default sorting of ls suits us, we can shorten it.
sort -n - must be used when there are files like 0001 - normal files are here and they will be sorted as expected.
find . -name "*.jar" ! -name "$(ls -1 *.jar | head -n1)" -delete
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question