Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 1 down vote accepted

You need to break this into two parts

1) Convert from bz2 to xz, which 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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .