Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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
share|improve this answer
add comment

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.

share|improve this answer
    
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
    
Not the inside a file, but of the archive itself. I want to repack a lot of bzip2 backups with xz and timestamp of archive is valuable information in my case. –  osgx Aug 15 '11 at 22:29
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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