0

I'm looking for a solution to create a tar.bz2 file and keep the original folder timestamp. My solution is "touch -t {original timestamp}" file.tar.bz2

manuel@mfpanzuela:~$ ls -la
drwxrwxr-x  2 manuel manuel     4096 nov 13  2013 cmdb

manuel@mfpanzuela:~$ tar cjf cmdb.tar.bz2 cmdb

-rw-rw-r--  1 manuel manuel      860 may 20 11:28 cmdb.tar.bz2
manuel@mfpanzuela:~$ touch -t 201311130000 cmdb.tar.bz2

manuel@mfpanzuela:~$ ls -la
drwxrwxr-x  2 manuel manuel     4096 nov 13  2013 cmdb
-rw-rw-r--  1 manuel manuel      860 nov 13  2013 cmdb.tar.bz2

Any idea to do it better ?

2 Answers 2

2

The timestamp of your archive file is of course not the one of the directory, since the archive is technically something totally new. But the files and directories inside the archive will remain their own timestamps.

Of course you can change the timestamp afterwards, and you don't even need to extract the filestamp from the directory, just reference it using -r:

touch -r cmdb cmdb.tar.bz2

(AFAIK, the -r option to touch conforms to POSIX standards.)

2
  • Yes, -r is posix compliant although if someone tags their question linux they're not necessarily worried about that I guess.
    – user9517
    May 20, 2014 at 10:23
  • Thank you Dubu, it's simple and perfect !! This is what I mean with better :)
    – mferpan
    May 20, 2014 at 10:25
1

What do you mean by "better? If you want to script it, you could combine it like this:

touch -d @`stat -c "%Y" cmdb` cmdb.tar.bz2 

or something like this, but if your approach works, it's fine.

(man touch, man stat).

You must log in to answer this question.

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