Rich Kulawiec via plug on 29 Oct 2020 00:58:43 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Copying files to multiple volumes |
On Wed, Oct 28, 2020 at 05:11:19PM -0400, Walt Mankowski via plug wrote: > My fallback is to run `du -b --max-depth=1`, load the output into a > spreadsheet, and hope that I can find point in the middle that leaves > half on each side. But I'm hoping there might be something to automate > it. It's probably not worth coming up with an automated solution for a one-time application, but here's something I've used to do what you suggest -- finding a point in the middle that roughly splits the total. du -sm * | awk -f /some/path/to/add.awk where add.awk is: BEGIN { tot = 0 } /^.*/ {tot = tot + $1; print $0, " ", tot} END { print tot} (Note that there are tab characters in there.) You might wonder this is awk and not Perl...well, that's because it was written well before Perl existed. That little three-line awk script has a lot of miles on it. Anyway, the -s flag to du tells it to summarize by directory, the -m flag says to use megabytes as the units. (Salt to taste if you want kbytes or gbytes.) The output of the awk script is its input plus a running total to the right, e.g. when the incantation above is run in a directory with the last five OpenBSD distributions, it yields: 1322 openbsd-6.4 1322 1451 openbsd-6.5 2773 1525 openbsd-6.6 4298 1540 openbsd-6.7 5838 1658 openbsd-6.8 7496 7496 Sooooo, look at the number at the bottom, divide by 2, scroll back up to find out where it shows up on the right. In this case, 3748 isn't there but 4298 is probably close enough. If the list is too long to scroll through, redirect the output to a file and use a text editor. ---rsk ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug