0

I have multiple zip files in a directory and its sub directories with the pattern ACCT_DOC. example T.6593.ACCT_DOC.1054.1_0.20170220.111425.zip T.12561.ACCT_DOC.1003.1_0.20160121.221947.zip

I need a list of all the files matching the pattern ACCT_DOC that were created today. The YYYYMMDD is part of the file naming convention

i tried using find . -type f -name 'ACCT_DOC.date '+%Y%m%d'.zip' but it is not working. Please help

1 Answer 1

0

The following command should do the trick:

find . -type f -name "*.ACCT_DOC.*.zip" -mmin -$(($(($(date +%H) * 60)) + $(date +%M)))

From man find:

-mmin n File's data was last modified n minutes ago.

This output contains the whole path. If you want the basename of the file, simply pipe the resultset to awk:

find . -type f -name "*.ACCT_DOC.*.zip" -mmin -$(($(($(date +%H) * 60)) + $(date +%M))) \ | awk -F"/" '{ print $NF }'

$NF prints out the last element of the splitted path.

6
  • Worked great. Appreciate your help
    – user86683
    Feb 20, 2017 at 17:07
  • No problem. Don't forget to accept the answer if it was what you are looking for.
    – J. Pee
    Feb 20, 2017 at 17:12
  • The result set also has the directory path included like ./SUPLR_SPND_CHINA/eff/LDI_SS_CHINASAP/ACCT_DOC/ARCHIVE/T.6593.ACCT_DOC.1054.1_0.20170220.111425.zip. I need only the list of zip files
    – user86683
    Feb 20, 2017 at 17:21
  • I've edited the answer.
    – J. Pee
    Feb 20, 2017 at 17:31
  • -mmin -$(($(($(date +%H) * 60)) + $(date +%M))) , does this only select the files with today's date? . I have 2 files with today's Time Stamp but the result only had 1.
    – user86683
    Feb 20, 2017 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .