0

I want to create a tar archive which will have files and directories. I need to change the modification time of these files and directories so that their modification timestamp is the current date and time when I'm doing the compression. How may I do that in shell script?

3
  • 2
    touch all files before archiving them?
    – Kusalananda
    Commented Oct 27, 2018 at 10:40
  • How can i do that. Can you just tell the command to do that? What i can do on directories Commented Oct 27, 2018 at 10:42
  • 1
    It's touch. See man touch for details. Commented Oct 27, 2018 at 10:43

2 Answers 2

1

If you have GNU tar, you can use the --mtime option to store arbitrary modification times; in your case,

tar cf archive.tar --mtime="@$(date +%s)" ...

will use the current time for all modification times stored in the archive.

2
  • appreciate the answer Commented Oct 27, 2018 at 11:39
  • This is a good hint for libfind that is used by star and many other programs: it seems to be a good idea to add -chatime, -chctime, -chmtime primaries to modify these values in struct stat.
    – schily
    Commented Oct 27, 2018 at 22:21
0

To update the modification timestamp on everything under a directory dir (including the directory itself):

find dir -exec touch {} +

You would do this just before you create your tar archive of the dir directory.

2
  • Do you really like to shredder all time stamps in the file system?
    – schily
    Commented Nov 2, 2018 at 17:31
  • @schily Only in the directory that will be archived.
    – Kusalananda
    Commented Nov 2, 2018 at 19:49

You must log in to answer this question.

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