猫でもわかるWebプログラミングと副業

本業エンジニアリングマネージャー。副業Webエンジニア。Web開発のヒントや、副業、日常生活のことを書きます。

Linux のメモリ容量・CPUコア数・ディスク容量を確認する

f:id:yoshiki_utakata:20180308114546j:plain

メモリ容量

free コマンドを使います。-h オプションを付けるといい感じに表示してくれます。

-hhuman readable output (automatic unit scaling) 、つまり、人間に見やすいように結果を出力してくれます。

$ free -h
             total       used       free     shared    buffers     cached
Mem:          1.8G       593M       1.3G       124K       159M       223M
-/+ buffers/cache:       210M       1.6G
Swap:         1.0G        98M       925M

Mem:totalをみたら良いです。このサーバーのメモリは2GBくらいですね。

used が使用中、 free が未使用です。

CPUコア数

/proc/cpuinfo ファイルを見るとわかります。

$ cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 44
model name  : Intel(R) Xeon(R) CPU           L5640  @ 2.27GHz
stepping    : 2
microcode   : 26
cpu MHz     : 2266.747
cache size  : 12288 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 11
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer hypervisor lahf_lm arat epb dts
bogomips    : 4533.49
clflush size    : 64
cache_alignment : 64
address sizes   : 42 bits physical, 48 bits virtual
power management:

processor: 0 はプロセッサのID。

物理的にCPUが増えると processor: 1, processor: 2 と増えていきます。今回はCPUは1つしか無いので、processor: 0 しかありません。

それに続いているのが、そのプロセッサの詳細です。

cpu MHz などの情報が並んでいますが cpu core: 1 これがCPUのコア数です。このCPUのコアは1つのようです。

ディスク容量

df コマンドを使います。これも -h コマンドを付けると見やすく表示してくれます。

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  2.0G   16G  12% /
tmpfs           939M     0  939M   0% /dev/shm
/dev/sda1       240M   40M  188M  18% /boot

このサーバーは大体20Gくらいディスクを積んでいるようです。

OSのバージョンを調べる方法

$ cat /etc/issue
Scientific Linux release 6.7 (Carbon)

これは Scientific Linux 環境で試したものですが、Cent OS でも同じです。

参考

[試して理解]Linuxのしくみ ~実験と図解で学ぶOSとハードウェアの基礎知識

[試して理解]Linuxのしくみ ~実験と図解で学ぶOSとハードウェアの基礎知識

  • 作者:武内 覚
  • 発売日: 2018/02/23
  • メディア: 単行本(ソフトカバー)