
私は次のようにファイルをソートしようとしました。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
ただし、順序が正しく指定されていません。
参考書:
-h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)
私の使い方に問題がありますか?
答え1
あなたの質問に従って列番号も提供する必要があります。
ls -lh /boot | sort -hk5
これで、サイズ列である列5に基づいて出力をソートします。
ここで使用されているのh
は、コマンドが使用される場合は数字でls -lh /boot | sort -nk5
ソートされ、考慮されないことですK,M,G
。h
オプションが使用されると考慮されますK,M,G
。
ソートするには、ls -lhS /boot
roaimaが提案した方が良い選択肢です。