0
In a "backup" folder, where most subfolders are named with a date, like in the following example:
backup/
20190401/
(...)
20190429/
I want to list all folders whose name are dates greater than, let's say, "20190415".
The point here is that the naming format allows sorting names in alphanumeric order to get a date sorting, so I guess something should be done with sorting order and criteria, but what?
Thank you!
With this date format it doesn't matter: lexicographic and numeric comparisons will give the same result. – AFH – 2019-04-29T12:51:43.633
Sure. However, I'm looking to find a command to compare filenames together. 20190415 < 20190429 – Ninj – 2019-04-29T12:59:06.293
The
if
command will do this: the precise syntax will depend on the OS and shell. – AFH – 2019-04-29T13:01:40.583I'm on Ubuntu with bash. I tried with
if [ ${name1} -gt ${name2} ]
with no result – Ninj – 2019-04-29T13:05:47.447What do you mean by "with no result"? There is always a result, true or false. If there are other characters in the directory (such as trailing
/
) then you'll need to use lexicographic comparisonif [ "${name1}" ">" "${name2}" ]
. The quotes round the>
are needed for correct parsing, but it is good practice to use them in variable expansions. – AFH – 2019-04-29T13:23:15.397