LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-02-2010, 02:32 AM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
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 \;
 
Old 02-02-2010, 03:25 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
terminal command to move a file to another directory vipjag2 Linux - Newbie 7 05-11-2009 11:37 PM
Move file and change directory in one command Ztyx Linux - General 8 02-19-2009 05:09 AM
Why won't it let me copy or move a file from one directory to another? dewjunkie Linux - Newbie 4 01-23-2008 01:31 AM
how do i get permission to move file into directory timalan SUSE / openSUSE 2 08-24-2005 10:25 PM
Is it possible to move file from /dev to other directory? raindrop Linux - Hardware 2 11-13-2002 06:37 PM


All times are GMT -5. The time now is 11:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration