How to tar files with a sorted order?

ide*_*n42 12 linux tar sort

If you tar a directory recursively, it just uses the order from the os's readdir.

But in some cases it's nice to tar the files sorted.

What's a good way to tar a directory sorted alphabetically?


请注意,就本问题而言,典型 Linux 系统上的 gnu-tar 没问题。

mik*_*erv 20

对于 GNU tar

--sort=ORDER
 Specify the directory sorting order when reading directories.
 ORDER may be one of the following:

`none'
      No directory sorting is performed. This is the default.

`name'
      Sort the directory entries on name. The operating system may
      deliver directory entries in a more or less random order, and
      sorting them makes archive creation reproducible.

`inode'
      Sort the directory entries on inode number. Sorting
      directories on inode number may reduce the amount of disk
      seek operations when creating an archive for some file
      systems.
Run Code Online (Sandbox Code Playgroud)

您可能还想查看--preserve-order.

  • `--sort` 是在 tar 版本 1.28 中引入的。`--preserve-order` 与这个问题无关。 (11认同)