22
4
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.
2
@matthiaskrull I have unrelated reason for this, I am creating a OVA file (which is a tar file) for deploying VMs on VMWare ESX Server. The OVA needs files in a specific order inside it (The first file should be an OVF and so on ).
– xask – 2014-09-16T11:29:39.780@xask That is indeed a valid reason. And there is always the
--append
option for a specifically required order that can not easily be achived by sorting. – matthias krull – 2014-09-29T13:24:54.7731There is also a very good reason for this: performance on a very large file when you want to extract only a portion of it. Since its order is by default random, and you want to extract a file/directory, if it's ordered it will be faster, if it's not, it will need to scan the whole archive prior it knows it has finished. – StormByte – 2015-03-13T20:33:33.993
2Why do you want to do this? – matthias krull – 2010-08-05T15:02:54.697
Mostly, it's because I want to know how close the tar operation is to being completed. When the files are being loaded in random order, there's no way to tell with the -v flag. – Erick Robertson – 2010-08-05T16:01:05.080
2That's not entirely true; If you pipe the output to a file and know the number of files (say a quick find command), you can compare the -v output (wc -l) with the number of files from find to get a sense of progress... – Slartibartfast – 2010-08-06T01:45:23.280