LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Move old file to other directory (https://www.linuxquestions.org/questions/linux-newbie-8/move-old-file-to-other-directory-786360/)

elainelaw 02-02-2010 01:32 AM

Move old file to other directory
 
I have a directory , there are many files created in it , I want to use the command to move the files which elder than 30 days and gzip it and then move it to /tmp , and then remove those files , I tried use below command but not work , can advise how can I do it ? thx

find ~path -type f -mtime 30 -exec tar -zcvf - {} --remove-files > /tmp/oldfile.tgz \;

jschiwal 02-02-2010 02:25 AM

Your command is trying to run the tar program once for each file found.

You can use find to generate the list of files.

find ~path -type f -mtime +30 -print0 | xargs -0 tar -C ~path zcvf /tmp/oldfile.tgz -

For a very long list of files, it may be better to save the list of files and use that or use a limiting option of xargs.


All times are GMT -5. The time now is 09:38 PM.