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?
2 Answers
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.
-
-
This is a good hint for
libfind
that is used bystar
and many other programs: it seems to be a good idea to add-chatime
,-chctime
,-chmtime
primaries to modify these values instruct stat
.– schilyCommented Oct 27, 2018 at 22:21
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.
-
Do you really like to shredder all time stamps in the file system?– schilyCommented Nov 2, 2018 at 17:31
-
touch
all files before archiving them?touch
. Seeman touch
for details.