Find Gzip rename and mv

Hi all,
what i'm trying to configure its to the following,
find all files older then 1 min,gzip them ,rename/move with date and extension .gz (example tes.log_2012-07-26.gz) and trying to move them to another folder (gzipped),the command i'm typing its this,

find /home/charli/Desktop/test/ -type f -mmin +1 -exec gzip {} \; -exec mv {}.gz {}_`date +%F`.gz \; -exec mv {} /home/charli/Desktop/test/gzipped/ 

but it does only the first two options,gzips the files and rename/moves them with the correct date and extension,but it doesn't complete the third option to move the file to another directory (gzipped)

when executing the command i get the following

mv: can not stat of "/home/charli/Desktop/test/test.log": File or directory does not exist

any help would be appreciated.

Thanks in advance.

#!/bin/bash
find /home/charli/Desktop/test/ -type f -mmin +1 |
while read fname 
do 
  newname=${fname}_`date +%F`
  mv $fname $newname
  gzip $newname 
  mv $newname /home/charli/Desktop/test/gzipped/
done

you gain nothing by making the command a one-liner.

1 Like

Looks like you try moving the original file {}, which was deleted by gzip, not the renamed one
{}_`date +%F`.gz ...

-exec mv {}.gz {}_`date +%F`.gz \; -exec mv {} /home/charli/Desktop/test/gzipped/

Why don't you move in one go :

-exec mv {}.gz /home/charli/Desktop/test/gzipped/{}_`date +%F`.gz

This doesn't work at all :File or directory missing

Thanks any way.

---------- Post updated at 10:58 AM ---------- Previous update was at 10:56 AM ----------

Yes i'll gain nothing on doing this on one line,but it simply cos i want to execute this job manually and not on cron jod by calling a script once a time.
Any way to make it?

try -execdir if available with your version of find