Find the answer to your Linux question:
Results 1 to 6 of 6
I have 4 lines of code where I tar the doc files and then extract to some other location. Code: cd ${INSTALLER_BUILD_ROOT}/doc/ tar cvf build_doc.tar * cd $DOC_ROOT/doc tar xvf ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    59

    tar and extract in a single line

    I have 4 lines of code where I tar the doc files and then extract to some other location.
    Code:
    cd ${INSTALLER_BUILD_ROOT}/doc/
    tar cvf build_doc.tar *
    cd $DOC_ROOT/doc
    tar xvf ${INSTALLER_BUILD_ROOT}/doc/build_doc.tar
    Can I optimize it and reduce to a single line?

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Do you want to end up with an additional archive in $DOC_ROOT or do you merely want to copy the files?

    cp ${INSTALLER_BUILD_ROOT}/doc/* $DOC_ROOT/doc/
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    59
    Actually, I want to just copy the files. But I can't use cp command because I'm doing this copy on the network drive location which starts with //, and cp command ignores the Case. ( for ex: it will copy the Hello as hello, which I do not want)
    I want to use tar only.

  4. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Use the pipe. That's what it's there for.

  5. #5
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Code:
    # cd ${INSTALLER_BUILD_ROOT}/doc/; tar cf - . | (cd $DOC_ROOT/doc; tar xpf -)

  6. #6
    Just Joined!
    Join Date
    Apr 2007
    Posts
    59
    Thanks, this is what I was looking for!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...