modify cpdir to tar.gz output and delete source ?

Hello experts,
my newest challenge for you....

I have looked through cpdir found at
and i see where the files are actualy copied, line 87

                cpio $CpioOpt "$targetdir"
Is there a way to make this script tar.gz the files it copies,
then delete the source files if wanted ?  I guess instead of
copy move into archive....

I could just tar.gz the enitre folder, but the logs are too many and too large,
it would create one big blob, when the seperate tar.gz files are quicker
and lighter to manipulate

I think i should change it to something like,
               tar cuzf  "$CpioOpt".tar.gz -C "$targetdir"
but the syntax is probably far from correct.

Thats the first hurdle,
next would be to delete the source files, if everything was ok.

Thanks in advance !

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

> Is there a way to make this script tar.gz the files it copies,
I guess no, 'cause the these tools (tar, cpio, dd, etc.) build some sort of checksum and discard the result if the checksum fails. In such a case the "moved" data are lost, probably not what you want.
You have to write a script which copies single files (or some amount of files) and removes the sources after szccessfully coying.
Sounds very much like you need rsync.

ghboomAuthor Commented:
thanks but cpio is used in the original program, all I want to do is to change the compression method and later delete the original....

Tintin, thanks also ;) but Im just looking for an automated way to copy folders and files while only compressing the files, and placing them
localy .

As there are hundreds of files in /var/logs and they need pruning, I would rather not have to do it file by file !

The original shell script looks as if it copies folder structure first, then copies the files.

Thanks anyway, I guess I will try other forums....

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I'm not 100% sure what you are trying to acheive, but will make the following comment.

rsync is quite often used for copying, archiving, moving files locally.  It doesn't have to be remote.

Are you trying to archive old logs by creating a bunch of tar.gz files in an archive location?  If so, what's the reason you want multiple tar.gz files?  What criterea are you using to select the files?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>rsync is quite often used for copying, archiving, moving files locally.  It doesn't have to be remote

   True,  please credit to Tintin.
ghboomAuthor Commented:
sorry about that, my eyes are tired, i missed that !

With GNU tar you may use --remove-files option, man tar
'remove files after adding them to archive'.
With standard tar there is no such option, sorry.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.