modify cpdir to tar.gz output and delete source ?

Posted on 2006-04-22
Last Modified: 2013-12-26
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 !

Question by:ghboom
    LVL 51

    Expert Comment

    > 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.
    LVL 48

    Expert Comment

    Sounds very much like you need rsync.


    Author Comment

    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....

    LVL 48

    Accepted Solution

    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?

    LVL 38

    Expert Comment

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

       True,  please credit to Tintin.

    Author Comment

    sorry about that, my eyes are tired, i missed that !

    LVL 27

    Expert Comment

    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.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    ODBC Connection Logging, ADO.NET 6 44
    sum28 challenge 31 82
    twoTwo  challenge 35 72
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now