Well ok i’ll bite. (way off the OP post)

I’m a big proponent of using the switches to be sure and accurate , but in the 
case of the output of du I can’t see where it makes a difference.   The default 
is sorting each line as one whole field, and the output of du always starts 
with spaces and a number - so by definition that will always sort in an 
intuitive way - in fact I’ve not found an example where using nk1,1 changes the 
output in any way from just using sort (speaking on the output of du only).

The only difference I can find is a trumped up example whereby there is no 
numeric, then sort treats that as putting it after the numerics  (any character 
> than any number) and -n treats any non-numeric starting value as 0

such as
> cat test.txt | sort
-1file
001 file
01 file
011 file
11 file
110 file
12 file
file
> cat test.txt | sort -nk1,1
-1file
file
001 file
01 file
011 file
11 file
12 file
110 file

But still that wouldn’t happen with du as a du ouptut as du will output minimum 
0 for everything. So the switches are unneeded.

du nonwithstanding - 
-n would i think be confusing in cases where, like the above, you have mixed 
beginning numeric and alpha, as I would think most would expect sorting of the 
numerics first, then the alphas, and not the non-intuitive sorting of “file” in 
between “-1file” and “001file”  vs the former of having it after all the 
numerics.

Last - I think -k1,1 is pretty much superfluous here given the space separator 
between the numeric size and folder/file name (sort assumes any combo of spaces 
tabs are a field seperator by default) - as I read the man page  k[m.n,p.q] 
means sort  starting at the qth character (here 0) of the mth field (hear first 
field) and continue through the qth character (again 0) of the pth field (here 
1) - so k1,1 means the key is the entire first field - which would be the 
default if there was any space after it.

if there is a tie, then it moves to the next character.  Only in examples like 
the last one, would  -k[1,3] change the order.

> cat test.txt
d0000002 file3
d0000001 file2
d0000003 file1
> cat test.txt | sort -nk1,1
d0000001 file2
d0000002 file3
d0000003 file1
> cat test.txt | sort -nk1
d0000001 file2
d0000002 file3
d0000003 file1
> cat test.txt | sort -nk1,3
d0000003 file1
d0000001 file2
d0000002 file3

I could see using something like: 
cat test.txt | sort -nk1.8 (note period not comma)
y0000001 file2
x0000002 file3
z0000003 file1

to sort by the numeric at the end of the first field. But this again is a made 
up example not an output from du.

But I digress … this was fun! … wait what was I talking about...

Chad





> On Feb 19, 2016, at 9:35 AM, Paul Gilmartin 
> <0000000433f07816-dmarc-requ...@listserv.ua.edu> wrote:
> 
> On 2016-02-19, at 07:48, Bigendian Smalls wrote:
> 
>> Tim have you tried this from a shell at the root of your ZFS partition (or 
>> just root / )
>> 
>> du -sk | sort
>> 
> BTW, I'm more comfortable with:
> 
>    du -k | sort -nk1,1
> 
> -- gil
> 
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to