List files with Date Range and Zip it

Hi all,

I am using the below script which display the files in the folder with the date range we specify. I want to add extra functionality that,

The listing files should be zipped using gzip. I tried to add exec gzip at the last line but it is not working.

Suggestions please.

#!/bin/ksh
  #################################################
  ## File: findDateRange.sh
  ## Purpose: A script to find the files within
  ## a given date range
  #################################################
  echo "You have to provide the path, start date and the end date"
  echo
  echo "Enter the path to start search"
  read fpath
  echo "Please enter the start date in the format YYYYMMDD"
  read strtdt
  echo "please enter the end date in the format YYYYMMDD"
  read enddt
  touch -t ${strtdt}0000 /tmp/newerstart
  touch -t ${enddt}2359 /tmp/newerend
  #find ./ \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print
  find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -exec ls -l {} \;

Instead of listing ls-l, i used gzip option but its not working.

Thanks in Advance.

Try :

find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) | xargs gzip

Jean-Pierre.

1 Like

Hi Jean,

Thanks. Its working.

Is there any way to list only some particular file extensions. Instead of listing all.

Thanks in Advance.