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!
if
command will do this: the precise syntax will depend on the OS and shell.if [ ${name1} -gt ${name2} ]
with no result/
) 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.