Linux – How to tar files with a sorted order

linuxsorttar

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?


Note, for the purpose of this question, gnu-tar on a typical Linux system is fine.

Best Answer

For a 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.

You'll probably also want to look at --preserve-order.

Related Question