by mannschott · 6y ago · 0 comments
find * -print | rev | sort | rev |
tar --create --no-recursion --files-from - |
gzip
This clusters file types together and within file types and within that files with the same base name close together.This worked surprisingly well for my use cases, though you can imagine that packing and unpacking times were impacted by the additional head seeks caused by the rather arbitrary order in which this accesses files.
$ tar -zcvf file.tar.gz directory/
$ du -sh directory.tar.gz
57M directory.tar.gz
$ find directory/* -print | rev | sort | rev | \
tar --create --no-recursion --files-from - | \
gzip -c > directory.tar.gz
$ du -sh directory.tar.gz
55M directory.tar.gz
3.51% (2MB) reduction makes many sense here.-print is also unnecessary.
Simply use
find | decorate | sort | undecorate
dance on each line produced by find. Where decorate would add the start of each line the things you want to sort by and undecorate would remove them again.