4

How can I repack .bz2 archive to .xz format, if I want to save datestamp of file and its chmod-chown settings?

I can use any standard tools and xz, lzma, p7zip

2

You need to break this into two parts

1) Convert from bz2 to xz, which billc.cn answered

2) Fix the ownership, permissions and timestamp of the xz file to match the bz2.

chown "`stat --printf '%u:%g' file.bz2`" file.xz
chmod "`stat -c '%a' file.bz2`" file.xz
touch -a -d "`stat -c '%x' file.bz2`" file.xz
touch -m -d "`stat -c '%y' file.bz2`" file.xz
4

You can simply use bzcat to remove the bzip2 compression but keep the tar format and then pipe the results into xz:

bzcat file.tar.bz | xz > file.tar.xz

You can add your compression options to xz as usual, but just leave out the file name so the standard input is used.

  • and how " to save datestamp of file and its chmod-chown settings?" – osgx Aug 13 '11 at 8:28
  • The file meta info are stored in the tar file and is not handled by the compression algorithm. If you don't touch the tar, then nothing will be changed. If you compressed a file without tar, you have already lost all the meta info anyways. – billc.cn Aug 13 '11 at 23:46
  • sorry, I did not ask about "tar.bz2" but about "bz2". Tar was added in your answer by you. I want to save stamp of the File.bz2 (File.xz should have the same stamp). – osgx Aug 14 '11 at 8:25
  • In which case the question has nothing to do with bzip or xz because these formats do NOT store timestamps in the archive file. When you decompress, the timestamp of the compressed file will be used for the output. To set the timestamp of a file, you can use touch. ls has extra options to display the complete {creation, access, modification} times of your original file. – billc.cn Aug 15 '11 at 22:28
  • 1
    In this case use stat -c %X to get the raw values. Change X for Y and Z, to get modification and change time. See the man page for stat. – billc.cn Aug 15 '11 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.