command sort -h does not return a reasonable result [duplicate]












0
















This question already has an answer here:




  • How to list all files ordered by size

    10 answers




I tried to sort files using sort -h



algorithms@algorithms:~$ ls -lh /boot | sort -h
drwxr-xr-x 5 root root 4.0K Dec 28 16:19 grub
-rw------- 1 root root 4.2M Dec 5 13:10 System.map-4.18.0-13-generic
-rw------- 1 root root 4.2M Nov 14 21:30 System.map-4.18.0-12-generic
-rw------- 1 root root 8.2M Dec 5 13:11 vmlinuz-4.18.0-13-generic
-rw------- 1 root root 8.2M Nov 14 21:50 vmlinuz-4.18.0-12-generic
-rw-r--r-- 1 root root 1.5M Nov 14 21:30 abi-4.18.0-12-generic
-rw-r--r-- 1 root root 179K Jan 28 2016 memtest86+.bin
-rw-r--r-- 1 root root 17 Nov 14 21:30 retpoline-4.18.0-12-generic
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+.elf
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+_multiboot.bin
-rw-r--r-- 1 root root 212K Dec 5 13:10 config-4.18.0-13-generic
-rw-r--r-- 1 root root 212K Nov 14 21:30 config-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 18 15:47 initrd.img-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 28 16:25 initrd.img-4.18.0-13-generic


However, it does not sort reasonably.



Reference to the manual:



   -h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)


What's the problem with my usage?










share|improve this question















marked as duplicate by roaima, Kusalananda, Jeff Schaller, RalfFriedl, elbarna Jan 3 at 22:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • @roaima OP wants to know how to use of h option in sort.

    – P_Yadav
    Jan 3 at 8:29






  • 2





    Unclear: It is unknown what you mean by "reasonably".

    – Kusalananda
    Jan 3 at 8:31






  • 2





    @P_Yadav it looks like an XY problem. There's little point solving Y if X is wrong.

    – roaima
    Jan 3 at 9:47


















0
















This question already has an answer here:




  • How to list all files ordered by size

    10 answers




I tried to sort files using sort -h



algorithms@algorithms:~$ ls -lh /boot | sort -h
drwxr-xr-x 5 root root 4.0K Dec 28 16:19 grub
-rw------- 1 root root 4.2M Dec 5 13:10 System.map-4.18.0-13-generic
-rw------- 1 root root 4.2M Nov 14 21:30 System.map-4.18.0-12-generic
-rw------- 1 root root 8.2M Dec 5 13:11 vmlinuz-4.18.0-13-generic
-rw------- 1 root root 8.2M Nov 14 21:50 vmlinuz-4.18.0-12-generic
-rw-r--r-- 1 root root 1.5M Nov 14 21:30 abi-4.18.0-12-generic
-rw-r--r-- 1 root root 179K Jan 28 2016 memtest86+.bin
-rw-r--r-- 1 root root 17 Nov 14 21:30 retpoline-4.18.0-12-generic
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+.elf
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+_multiboot.bin
-rw-r--r-- 1 root root 212K Dec 5 13:10 config-4.18.0-13-generic
-rw-r--r-- 1 root root 212K Nov 14 21:30 config-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 18 15:47 initrd.img-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 28 16:25 initrd.img-4.18.0-13-generic


However, it does not sort reasonably.



Reference to the manual:



   -h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)


What's the problem with my usage?










share|improve this question















marked as duplicate by roaima, Kusalananda, Jeff Schaller, RalfFriedl, elbarna Jan 3 at 22:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • @roaima OP wants to know how to use of h option in sort.

    – P_Yadav
    Jan 3 at 8:29






  • 2





    Unclear: It is unknown what you mean by "reasonably".

    – Kusalananda
    Jan 3 at 8:31






  • 2





    @P_Yadav it looks like an XY problem. There's little point solving Y if X is wrong.

    – roaima
    Jan 3 at 9:47
















0












0








0









This question already has an answer here:




  • How to list all files ordered by size

    10 answers




I tried to sort files using sort -h



algorithms@algorithms:~$ ls -lh /boot | sort -h
drwxr-xr-x 5 root root 4.0K Dec 28 16:19 grub
-rw------- 1 root root 4.2M Dec 5 13:10 System.map-4.18.0-13-generic
-rw------- 1 root root 4.2M Nov 14 21:30 System.map-4.18.0-12-generic
-rw------- 1 root root 8.2M Dec 5 13:11 vmlinuz-4.18.0-13-generic
-rw------- 1 root root 8.2M Nov 14 21:50 vmlinuz-4.18.0-12-generic
-rw-r--r-- 1 root root 1.5M Nov 14 21:30 abi-4.18.0-12-generic
-rw-r--r-- 1 root root 179K Jan 28 2016 memtest86+.bin
-rw-r--r-- 1 root root 17 Nov 14 21:30 retpoline-4.18.0-12-generic
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+.elf
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+_multiboot.bin
-rw-r--r-- 1 root root 212K Dec 5 13:10 config-4.18.0-13-generic
-rw-r--r-- 1 root root 212K Nov 14 21:30 config-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 18 15:47 initrd.img-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 28 16:25 initrd.img-4.18.0-13-generic


However, it does not sort reasonably.



Reference to the manual:



   -h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)


What's the problem with my usage?










share|improve this question

















This question already has an answer here:




  • How to list all files ordered by size

    10 answers




I tried to sort files using sort -h



algorithms@algorithms:~$ ls -lh /boot | sort -h
drwxr-xr-x 5 root root 4.0K Dec 28 16:19 grub
-rw------- 1 root root 4.2M Dec 5 13:10 System.map-4.18.0-13-generic
-rw------- 1 root root 4.2M Nov 14 21:30 System.map-4.18.0-12-generic
-rw------- 1 root root 8.2M Dec 5 13:11 vmlinuz-4.18.0-13-generic
-rw------- 1 root root 8.2M Nov 14 21:50 vmlinuz-4.18.0-12-generic
-rw-r--r-- 1 root root 1.5M Nov 14 21:30 abi-4.18.0-12-generic
-rw-r--r-- 1 root root 179K Jan 28 2016 memtest86+.bin
-rw-r--r-- 1 root root 17 Nov 14 21:30 retpoline-4.18.0-12-generic
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+.elf
-rw-r--r-- 1 root root 181K Jan 28 2016 memtest86+_multiboot.bin
-rw-r--r-- 1 root root 212K Dec 5 13:10 config-4.18.0-13-generic
-rw-r--r-- 1 root root 212K Nov 14 21:30 config-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 18 15:47 initrd.img-4.18.0-12-generic
-rw-r--r-- 1 root root 38M Dec 28 16:25 initrd.img-4.18.0-13-generic


However, it does not sort reasonably.



Reference to the manual:



   -h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)


What's the problem with my usage?





This question already has an answer here:




  • How to list all files ordered by size

    10 answers








ls sort






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 10:47









Jeff Schaller

39.3k1054125




39.3k1054125










asked Jan 3 at 7:53









JawSawJawSaw

984417




984417




marked as duplicate by roaima, Kusalananda, Jeff Schaller, RalfFriedl, elbarna Jan 3 at 22:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by roaima, Kusalananda, Jeff Schaller, RalfFriedl, elbarna Jan 3 at 22:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • @roaima OP wants to know how to use of h option in sort.

    – P_Yadav
    Jan 3 at 8:29






  • 2





    Unclear: It is unknown what you mean by "reasonably".

    – Kusalananda
    Jan 3 at 8:31






  • 2





    @P_Yadav it looks like an XY problem. There's little point solving Y if X is wrong.

    – roaima
    Jan 3 at 9:47





















  • @roaima OP wants to know how to use of h option in sort.

    – P_Yadav
    Jan 3 at 8:29






  • 2





    Unclear: It is unknown what you mean by "reasonably".

    – Kusalananda
    Jan 3 at 8:31






  • 2





    @P_Yadav it looks like an XY problem. There's little point solving Y if X is wrong.

    – roaima
    Jan 3 at 9:47



















@roaima OP wants to know how to use of h option in sort.

– P_Yadav
Jan 3 at 8:29





@roaima OP wants to know how to use of h option in sort.

– P_Yadav
Jan 3 at 8:29




2




2





Unclear: It is unknown what you mean by "reasonably".

– Kusalananda
Jan 3 at 8:31





Unclear: It is unknown what you mean by "reasonably".

– Kusalananda
Jan 3 at 8:31




2




2





@P_Yadav it looks like an XY problem. There's little point solving Y if X is wrong.

– roaima
Jan 3 at 9:47







@P_Yadav it looks like an XY problem. There's little point solving Y if X is wrong.

– roaima
Jan 3 at 9:47












1 Answer
1






active

oldest

votes


















6














According to your question, you have to also provide the column number i.e.



ls -lh /boot | sort -hk5


Now it will sort the output based upon the column 5 i.e. column which represents size.



Here the use of h is, if you use the command ls -lh /boot | sort -nk5, then it will sort according to the numbers without considering K,M,G, and if you use h option, then it will consider K,M,G.



If you want to sort then better option is ls -lhS /bootas suggested by roaima.






share|improve this answer





















  • 2





    But ls -lhS /boot will avoid the need to pipe into sort at all

    – roaima
    Jan 3 at 8:25


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














According to your question, you have to also provide the column number i.e.



ls -lh /boot | sort -hk5


Now it will sort the output based upon the column 5 i.e. column which represents size.



Here the use of h is, if you use the command ls -lh /boot | sort -nk5, then it will sort according to the numbers without considering K,M,G, and if you use h option, then it will consider K,M,G.



If you want to sort then better option is ls -lhS /bootas suggested by roaima.






share|improve this answer





















  • 2





    But ls -lhS /boot will avoid the need to pipe into sort at all

    – roaima
    Jan 3 at 8:25
















6














According to your question, you have to also provide the column number i.e.



ls -lh /boot | sort -hk5


Now it will sort the output based upon the column 5 i.e. column which represents size.



Here the use of h is, if you use the command ls -lh /boot | sort -nk5, then it will sort according to the numbers without considering K,M,G, and if you use h option, then it will consider K,M,G.



If you want to sort then better option is ls -lhS /bootas suggested by roaima.






share|improve this answer





















  • 2





    But ls -lhS /boot will avoid the need to pipe into sort at all

    – roaima
    Jan 3 at 8:25














6












6








6







According to your question, you have to also provide the column number i.e.



ls -lh /boot | sort -hk5


Now it will sort the output based upon the column 5 i.e. column which represents size.



Here the use of h is, if you use the command ls -lh /boot | sort -nk5, then it will sort according to the numbers without considering K,M,G, and if you use h option, then it will consider K,M,G.



If you want to sort then better option is ls -lhS /bootas suggested by roaima.






share|improve this answer















According to your question, you have to also provide the column number i.e.



ls -lh /boot | sort -hk5


Now it will sort the output based upon the column 5 i.e. column which represents size.



Here the use of h is, if you use the command ls -lh /boot | sort -nk5, then it will sort according to the numbers without considering K,M,G, and if you use h option, then it will consider K,M,G.



If you want to sort then better option is ls -lhS /bootas suggested by roaima.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 12:01

























answered Jan 3 at 8:08









P_YadavP_Yadav

1,5883923




1,5883923








  • 2





    But ls -lhS /boot will avoid the need to pipe into sort at all

    – roaima
    Jan 3 at 8:25














  • 2





    But ls -lhS /boot will avoid the need to pipe into sort at all

    – roaima
    Jan 3 at 8:25








2




2





But ls -lhS /boot will avoid the need to pipe into sort at all

– roaima
Jan 3 at 8:25





But ls -lhS /boot will avoid the need to pipe into sort at all

– roaima
Jan 3 at 8:25



Popular posts from this blog

Morgemoulin

Scott Moir

Souastre