Regex/bash find string with most recent date? -


for personal backup scheme, have set of folders names in pattern (something)_(day)(month)(year)_t(hour)(minute)(second). here's sample:

01.hourly_02102016_t171011 00.daily_27092016_t102203 00.weekly_17032015_t050600 

i want select list folder recent time in name. how in bash script?

perhaps, shortest command:

ls -1 | sort -t_ -k2.5nr,2 -k2.3nr,2 -k2.1nr,2 -k3r 

it sorts years, months, , days, in order. -t option specifies field separator column numbers used in -k option values.

the -kx.ynr,2 options stand sorting column x, character number y in reverse (r) numeric order (n); stop sorting @ column 2 (the last character after comma).

          -k2.5 ··············v 00.weekly_17032015_t050600           ^^^^^^^^           column 2 

the last -k3r sorts third column in reverse order.

the recent @ top of list. can select appending | head -1 end of command.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -