as i get more and more settled into a mindset of low time preference, one of the things that i'm getting a lot of improvement on is my skills working with shell tricks...

i finally can do something i've been always wishing for - to archive a specific set of files into a compressed tar archive.

this command tars up and xz compresses at max setting all of the 'hidden' dotfiles in your home directory:

# tar c `ls -a|grep ^[.][^.].*`|pv -s `ls -a|grep ^[.][^.].*|xargs du -d0 --total -b|grep total|cut -f1`|xz -9>dotfiles.tar.xz

that little one-liner finds all the files and folders starting with a dot '.' that get hidden by default in unix 'ls' listings, counts up the total data size, then strings all the files together using tar, from that total count of bytes estimates an ETA and gives a progress bar, and finally, compresses it with maximum compression using the most efficient compressor, xz.

high time preference made me not stop and learn how to do such a thing, but now it lets me do that, and now i can offload some of my work and attention requirement to the computer while i comfortably know that all my home directory profile data is going to be neatly zipped up and i know when it's going to be finished so i can just set the terminal to read only and leave it running in the background until it finishes.

it's 27gb btw... much of that is caches from yay AUR builds of custom packages.

gonna do it with my source code folder, from GOPATH days i still keep all my files in a directory 'src' which is the old gopath location for source code before the abomination called modules appeared and enabled idiocy like what is happening to btcd.

yea, verily, i would cancel go modules altogether if i had any say in it, and take a different approach where go understood that each repository in the src/path/to/repo name (eg src/github.com/btcsuite/btcd) was a Git repository and to make a temporary directory tree, unpack the modules on the tag specified in the go.mod, and that whole thing would be easily accessed by a dotfolder .build in the repository when i run 'go run ... or go build ...' and see exactly what it did.

well, modules does that somewhere still, it's just not very transparent. one of my main gripes with the go tool is its either telling you nothing or telling you way too much if you set -x. -v doesn't hardly print anything, and no flag is zero print at all except sometimes which is random.

anyhoo, enjoy playing with pipes, my fellow unix shell user developers.

Reply to this note

Please Login to reply.

Discussion

speaking of source directory trees, here is a one-liner that does the same thing to archive that, with a progress bar and max compression:

tar c src|pv -s `du -d0 --total -b src|grep total|cut -f1`|xz -9>src.tar.xz

note that in both cases, if you are aiming to make a snapshot that doesn't wind up with momentary changed files out of sync (like, browser cache/state data is likely to be mangled if it takes ages to get through it), better to remove the '|xz -9` and remove the `.xz` at the end on both and then `xz -9 src.tar` `xz -9 dotfiles.tar` to finish the job.