0

Hi I want to list filenames in a directory having timestamp in its file name. For example: gn_752_pos_id_n_00_000_9_20200331.dat.gz gn_40006_dep_ip_c_qa_500_2_20200331_20200622T082432.dat.gz

So I want to get a list of files having timestamp format like '20200622T082432'.

I tried the following command but it didn't work. find . -type f | xargs ls -l --time-style="yyyyMMdd'T'HHmmss"

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
chinmoy
  • 11

1 Answers1

0

I think you want to glob files whose name contains the pattern:

8 digits T 6 digits

You can do that like this:

ls *[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]*

In practice, that is rather unwieldy, so you might define an alias:

alias ts='ls *[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]*'

Then you can just use:

ts

Or, you might find that a less rigorous test requiring only a single digit either side of T is enough for most purposes:

ls *[0-9]T[0-9]*

You could also leverage a "regular expression" with a specific number of repetitions (i.e. 8 digits, T, 6-digits) like this GNU find:

find . -regextype posix-extended -regex ".*[0-9]{8}T[0-9]{6}.*"
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432