command sort -h does not return a reasonable result [duplicate]
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?
ls sort
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.
add a comment |
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?
ls sort
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 ofh
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
add a comment |
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?
ls sort
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
ls sort
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 ofh
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
add a comment |
@roaima OP wants to know how to use ofh
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
add a comment |
1 Answer
1
active
oldest
votes
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 /boot
as suggested by roaima.
2
Butls -lhS /boot
will avoid the need to pipe intosort
at all
– roaima
Jan 3 at 8:25
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 /boot
as suggested by roaima.
2
Butls -lhS /boot
will avoid the need to pipe intosort
at all
– roaima
Jan 3 at 8:25
add a comment |
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 /boot
as suggested by roaima.
2
Butls -lhS /boot
will avoid the need to pipe intosort
at all
– roaima
Jan 3 at 8:25
add a comment |
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 /boot
as suggested by roaima.
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 /boot
as suggested by roaima.
edited Jan 3 at 12:01
answered Jan 3 at 8:08
P_YadavP_Yadav
1,5883923
1,5883923
2
Butls -lhS /boot
will avoid the need to pipe intosort
at all
– roaima
Jan 3 at 8:25
add a comment |
2
Butls -lhS /boot
will avoid the need to pipe intosort
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
add a comment |
@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