mac lsコマンドでファイルサイズをMやKなどの単位で表示する

macのターミナル上で、lsコマンドでファイルサイズをMやKなどの単位で表示する手順を記述してます。オプション「h」を使用します。様々なコマンドで使用するので是非覚えて下さい。
環境
- OS macOS Monterey
- SHELL /bin/zsh
MやKなどの単位で表示
MやKなどの単位で表示するには、オプション「-h」を使用します。
試しに、「ls」コマンドに「-h」を使用して実行してみます。
% ls -lh
<出力結果>
total 1400
drwx------+ 4 admin staff 128B Jan 5 2021 Desktop
drwx------+ 3 admin staff 96B May 23 2019 Documents
drwx------+ 4 admin staff 128B Aug 16 2019 Downloads
drwx------@ 81 admin staff 2.5K Jul 10 21:08 Library
drwx------+ 5 admin staff 160B Jul 10 19:36 Movies
drwx------+ 6 admin staff 192B Jul 10 19:26 Music
drwx------+ 5 admin staff 160B Oct 19 2020 Pictures
drwxr-xr-x+ 5 admin staff 160B Jul 10 19:36 Public
drwxr-xr-x 3 admin staff 96B Sep 13 09:47 bar
-rw-r--r-- 1 admin staff 12B Sep 6 09:45 foo.txt
drwxr-xr-x 6 admin staff 192B Sep 10 12:53 hoge
-rw-r--r-- 1 admin staff 26B Sep 3 14:51 hoge.txt
-rw-r--r-- 1 admin staff 85K Sep 10 12:29 index.html
-rw-r--r-- 1 admin staff 151B Sep 7 09:24 ping.log
-rw-r--r-- 1 admin staff 151B Sep 7 09:24 ping2.log
drwxrwxr-x 7 admin staff 224B Sep 14 11:49 test
-rw-r--r-- 1 admin staff 12B Sep 8 09:45 test.txt
-rw-r--r-- 1 admin staff 590K Sep 7 09:06 zoom.jpg
容量が「K」などの単位がついて表示されていることが確認できると思います。
「df」コマンドでも「-h」をつけると、単位をつけて表示してくれます。
% df -h
<出力結果>
/dev/disk1s5s1 113Gi 14Gi 18Gi 45% 553781 1182288699 0% /
devfs 189Ki 189Ki 0Bi 100% 655 0 100% /dev
/dev/disk1s4 113Gi 2.0Gi 18Gi 10% 3 1182842477 0% /System/Volumes/VM
/dev/disk1s2 113Gi 305Mi 18Gi 2% 1160 1182841320 0% /System/Volumes/Preboot
/dev/disk1s6 113Gi 640Ki 18Gi 1% 17 1182842463 0% /System/Volumes/Update
/dev/disk1s1 113Gi 77Gi 18Gi 81% 1365785 1181476695 0% /System/Volumes/Data
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /System/Volumes/Data/home
-
前の記事
sakuraエディタ メニューバーの表示・非表示を切り替えるショートカットキー 2022.11.22
-
次の記事
Windows PostgreSQLをコマンドプロンプトから使用する 2022.11.22
コメントを書く