0

I'm having an issue while trying to parse a date/time string in inside the find function. Anybody has any idea how to solve this? Many thanks.

src_dir="/Users/user/directory/subdirectory"

start_dt='2018-08-15'
end_dt='2018-08-21'


find src_dir -name "*.txt" -newermt start_dt ! -newermt end_dt -exec ls -l "{}" \;


Result: " find: Can't parse date/time: start_dt "

Tomas Nemeth
  • 95
  • 2
  • 12
  • 4
    To get the value of a variable, precede it with `$`. It's also generally a good idea to put double-quotes around it in case it contains whitespace or wildcards, as in `find "$src_dir" -name "*.txt" -newermt "$start_dt" ! -newermt "$end_dt" -exec ls -l "{}" \;` – Gordon Davisson Aug 26 '18 at 00:36
  • Hi, many thanks! Your suggestion did work for me.. I just had to precede the variables Start_dt and End_dt with "$". start_dt='2018-08-15' end_dt='2018-08-21' find src_dir -name "*.txt" -newermt $start_dt ! -newermt $end_dt -exec ls -l "{}" \; – Tomas Nemeth Aug 26 '18 at 09:38

1 Answers1

0

I think you need to change the "date strings" to timestamps. Try

start_dt=`date --date='2018-08-15' +%s`
end_dt=`date --date='2018-08-21' +%s`

This was suggested here

7 Reeds
  • 2,419
  • 3
  • 32
  • 64