Find Gzip rename and mv


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find Gzip rename and mv
# 1  
Old 07-26-2012
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,
Code:
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

Code:
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.
# 2  
Old 07-26-2012
Code:
#!/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.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 07-26-2012
Looks like you try moving the original file {}, which was deleted by gzip, not the renamed one
{}_`date +%F`.gz ...

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

Why don't you move in one go :
Code:
-exec mv {}.gz /home/charli/Desktop/test/gzipped/{}_`date +%F`.gz

# 4  
Old 07-26-2012
Quote:
Originally Posted by RudiC
Looks like you try moving the original file {}, which was deleted by gzip, not the renamed one
{}_`date +%F`.gz ...

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

Why don't you move in one go :
Code:
-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 ----------

Quote:
Originally Posted by jim mcnamara
Code:
#!/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.
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?
# 5  
Old 07-27-2012
try -execdir if available with your version of find
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Hpux find tar gzip

Hello, I will like to execute a find, tar & gzip in one command. find * -type f -mtime -$nb_days -print | xargs tar -cvf $MAITUT/BCK_DATA.tar gzip $MAITUT/BCK_DATA.tar.gz The fact that the TAR is very big, at the end I need to generate only a compress file. Please note... (22 Replies)
Discussion started by: royinfo.alain
22 Replies

2. UNIX for Beginners Questions & Answers

Need help ASAP - FIND - TAR - GZIP

Hi, I need to combined in 1 line the execution below : find * -type f -mtime -$nb_days -print | xargs tar -cvf $MAITUT/BCK_DATA.tar gzip $MAITUT/BCK_DATA.tar.gz The fact that the TAR is very big, at the end I need to generate only the GZ file. The option z on the tar... (2 Replies)
Discussion started by: royinfo.alain
2 Replies

3. Shell Programming and Scripting

Is better way copy list of multiple files, rename and gzip

Is better way to write the script loop through one by one "Old_File_1: & New_File_1:" to copy 100 files to /staging/test folder then re-name & gzip all those files? I wrote this code below and don't like that much. Thanks I have a control_file under /tmp/test folder like below 100 files and... (10 Replies)
Discussion started by: dotran
10 Replies

4. Shell Programming and Scripting

Some help with a find/fuser/gzip crontab job

Hello, I am trying to write a housekeeping that finds all .trc files older than x days in a given FS, checks if they are used and gzips them if they are not used by any process. I need to do it without calling any additional .sh script. I managed to make it work for Linux only: find .... (4 Replies)
Discussion started by: Valkov
4 Replies

5. UNIX for Dummies Questions & Answers

Failed to use find-tar-gzip together

Hello I am trying to select multiple files older than 14 days and create a single compressed file out of it. (AIX Release 3 Version 5) I am trying to achieve it by following tar -cvf db01_log.tar `find . -name "db01*.log" -mtime +14" -print`| gzip > db01_log.tar however it just... (7 Replies)
Discussion started by: Chetanz
7 Replies

6. Shell Programming and Scripting

find + tar + gzip + uunecode/email --> in one command?

How to search for all files with matching strings --> find + tar + gzip + uunecode/email them in one command? I am sure there is a right way to pass list of files to tar, then compress tar file. Then send that as attachment using uuencode in one command.. Can we do that!? (3 Replies)
Discussion started by: kchinnam
3 Replies

7. Solaris

How to find out bottleneck if system is taking long time in gzip

Dear All, OS = Solaris 5.10 Hardware Sun Fire T2000 with 1 Ghz quode core We have oracle application 11i with 10g database. When ever i am trying to take cold backup of database with 55GB size its taking long time to finish. As the application is down nobody is using the server at all... (8 Replies)
Discussion started by: yoojamu
8 Replies

8. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

9. Shell Programming and Scripting

Find and Rename files using (find mv and sed)

In response to a closed thread for degraff63 at https://www.unix.com/shell-programming-scripting/108882-using-mv-find-exec.html the following command might do it as some shells spit it without the "exec bash -c " part: Find . -name "*.model" -exec bash -c "mv {} \`echo {} | sed -e 's//_/g'\`"... (0 Replies)
Discussion started by: rupert160
0 Replies

10. UNIX for Dummies Questions & Answers

Combining find, grep and gzip

I'm trying to see which files have a particular word in them. The files are all text files but are gzipped and are in sub directories. In order to view the content of a single gzipped file I tried: cat filename | gzip -d | less , and it shows the files contents. But, I want to see a list... (1 Reply)
Discussion started by: thoughts
1 Replies
Login or Register to Ask a Question