Question: I want to create a tar file where all of the directories and files are processed in alphabetical order. This is for the entire directory hierarchy that's being tarred up, so it would start by processing the first directory alphabetically, and then sub-directories in there alphabetically, etc. I looked through the man page and can't find a switch for this.

I will admit, this is half novelty, half slight optimization. I just can't believe that there isn't an easy way to do this. I must be missing something.

Answer: 
The order of the files within the tar file does not really matter, since when the files are extracted, the filesystem will not preserve the order anyway.

There is no switch for this, but if you really wanted it, you could provide tar with a list of filenames in sorted order, and it would create the tar file with the order you give it.

```
% tar cf tarfile tmp/diff.txt src/hellow.c junkimage.IMG barry/thegroup
% tar tf tarfile
tmp/diff.txt
src/hellow.c
junkimage.IMG
barry/thegroup

```
Assuming you don't have any files with newlines in the names:

```
find /source_directory -print | sort | tar -czf target.tgz -T -

```

If that doesn't work (never tried it, so I don't know of - means stdin for the -T argument):

```
find /source_directory -print | sort > /tmp/temporary_file_list
tar -czf target.tgz -T /tmp/temporary_file_list

```

Then there is the question of why. But sometimes it is easier not to ask.