在 Windows 上打包文件并保留文件夹时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5397957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:29:04  来源:igfitidea点击:

pack files on windows and preserve folder timestamps

windowszipgziparchivetar

提问by BetaRide

I want to put a big folder on Windows box into one archive (tar, zip, gzip, whatever). Is there a tool that can preserver all folder timestamps?

我想将 Windows 盒子上的一个大文件夹放入一个存档(tar、zip、gzip 等)中。有没有可以保留所有文件夹时间戳的工具?

The timestamps have to be preserverd after unpacking the archive on a Linux box.

在 Linux 机器上解压存档后,必须保留时间戳。

Any ideas are welcome!

欢迎任何想法!

采纳答案by Erik

tar will do fine. gzip is for single file compression, zip won't preserve directory timestamps.

焦油会很好。gzip 用于单个文件压缩,zip 不会保留目录时间戳。

EDIT: Sample.

编辑:示例。

tar jcpf backup.tbz2 thedir
rm -rf thedir
tar jxpf backup.tbz2

Timestamps preserved.

时间戳被保留。

EDIT2:

编辑2:

cygwin tarcorrectly preserves timestamps. Tested with tar jcfon cygwin, tar jxfon linux.

cygwintar正确保留时间戳。tar jcf在 cygwintar jxf上测试,在 linux 上。

EDIT3: WinRar preserves directory timestamps, linux unrarrestores them properly.

EDIT3:WinRar 保留目录时间戳,linuxunrar正确恢复它们。

回答by Cheeso

DotNetZip preserves timestamps on folders, as well as files.

DotNetZip 保留文件夹和文件上的时间戳。

回答by BetaRide

It seams that there's no soluation to all my requirements:

看来我的所有要求都没有解决方案:

  1. Pack on Windows an preserve folder timestamps
  2. Unpack on Linux and preserve original folder timestamps
  3. I prefer a copy/paste aka portable installation of the tool, otherwise the deployment gets to complicated.
  4. A partial, drop in cygwin installation by just copying the necessary exe and dll files works, but doesn't preserve the folder timestamps.
  5. Full cygwin installation is not easily possible since the windows client machines are on terminal server (see http://www.cygwin.com/faq/faq.setup.html#faq.setup.setup-fails-on-ts)
  6. Zip doesn't work because unzip on ubuntu cannot preserver folder timestamps, even if the zip tool of choice does.
  1. 在 Windows 上打包保留文件夹时间戳
  2. 在 Linux 上解压并保留原始文件夹时间戳
  3. 我更喜欢复制/粘贴也就是该工具的便携式安装,否则部署会变得复杂。
  4. 只需复制必要的 exe 和 dll 文件即可在 cygwin 安装中进行部分删除,但不会保留文件夹时间戳。
  5. 完整的 cygwin 安装并不容易,因为 Windows 客户端机器在终端服务器上(参见http://www.cygwin.com/faq/faq.setup.html#faq.setup.setup-fails-on-ts
  6. Zip 不起作用,因为在 ubuntu 上解压缩无法保留文件夹时间戳,即使选择的 zip 工具可以。