3

I am using the below command to find files which are greater than particular size and zip it. How can I modify the below command to include the timestamp at the end of the file?

find . -type f -name "*querry_match*" -size +550000000c -exec gzip {} \;

Expectation,

Before zipping:  querry_match_file1

After zipping:   querry_match_file1.`date +"%m-%d-%Y-%H:%M:%S"`.z
                 querry_match_file1.09-24-2015-02:50:56.z
Thushi
  • 9,498

1 Answers1

4

If by timestamp you mean "now", rather than the time of the file, you can try something like this:

find . -type f -name "querry_match" -size +550000000c \
 -exec bash -c 'gzip --suffix $(date +".%m-%d-%Y-%H:%M:%S.z") {}' \;

where the date command is run separately for each file. If your want the same date on all files, as at the start of the find, simply do:

find . -type f -name "querry_match" -size +550000000c \
 -exec gzip --suffix $(date +".%m-%d-%Y-%H:%M:%S.z") {} \;
meuh
  • 51,383
  • thank you very much. It works fine. Was able to figure out one more alternative

    find . -type f -name "*querry*" -size +55c -exec gzip "{}" \; -exec mv "{}.z" "{}date +".%m-%d-%Y-%H:%M:%S.z"" \;

    – Chittha Shetty Sep 25 '15 at 08:14