LoginSignup
5
6

More than 3 years have passed since last update.

Linuxコマンドの備忘録

Last updated at Posted at 2017-11-09

私がLinuxのコマンドでよく使うけれでも、忘れてしまうコマンドが多数ある。
備忘録のために、Linuxのコマンドをまとめておく。

環境

  • centos7.1
  • apache2.4
  • php7.0
  • mysql5.6

コマンド集

■ OSのバージョンを確認する

コマンド
$ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)

■ CPUを確認する

コマンド
$ cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 61
model name      : Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
stepping        : 4
cpu MHz         : 2394.454
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0

 ・・・

cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

■ メモリを確認する

参考)
http://enakai00.hatenablog.com/entry/20110906/1315315488

コマンド
$ cat /proc/meminfo 
MemTotal:        3882808 kB
MemFree:          109492 kB
MemAvailable:     993868 kB
Buffers:               0 kB
Cached:           904448 kB
SwapCached:        69764 kB
Active:          2099140 kB
Inactive:        1306020 kB

 ・・・

Hugepagesize:       2048 kB
DirectMap4k:       36800 kB
DirectMap2M:     4157440 kB

■ メモリの使用状況を確認する

コマンド
$ free
              total        used        free      shared  buff/cache   available
Mem:        3882808     2648500      380332        4028      853976      924900
Swap:       1048572      501436      547136

■ IPアドレスを確認する

コマンド
$ ifconfig

## すべて表示するなら-aをつける
$ ifconfig -a

■ ディスク使用量を確認する

コマンド
$ df
Filesystem              1K-blocks      Used Available Use% Mounted on
/dev/mapper/centos-root 155697940  40491580 115206360  27% /
devtmpfs                  1931960         0   1931960   0% /dev
tmpfs                     1941404         0   1941404   0% /dev/shm
tmpfs                     1941404      8612   1932792   1% /run

## 見やすい単位で表示するには、-hをつける
$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  149G   39G  110G  27% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.5M  1.9G   1% /run

■ ディレクトリの使用量を確認する

オプションの詳細については、du --helpで確認してね。

コマンド
$ du -sch /var/www/*
19G     /var/www/backup
0       /var/www/cgi-bin
353M    /var/www/html
14G     /var/www/tmp
33G     total

■ apacheモジュールを確認する

コマンド
$ httpd -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 access_compat_module (shared)
 actions_module (shared)
 alias_module (shared)

 ・・・

 ssl_module (shared)
 systemd_module (shared)
 cgi_module (shared)
 php7_module (shared)

■ PHP(CLI)の情報を表示する

コマンド
## PHP(CLI)の設定情報を表示する
$ php -i

## PHPのバージョンを確認する
$ php -v

## PHP(CLI)で利用できるモジュールのリストを表示する
$ php -m 

■ ファイル内の文字列をまとめて置換する

参考)https://qiita.com/kkyouhei/items/b4ff839a2f36ba194df3

コマンド
$ grep -l '置換対象の文字列' 置換対象のファイル | xargs sed -i.bak -e 's/置換対象の文字列/置換後の文字列/g'

■ MySQLのDB、テーブルサイズの確認

(参考) https://qiita.com/ikenji/items/b868877492fee60d85ce

DBのサイズ

mysqlコマンド
SELECT 
    table_schema, sum(data_length) /1024/1024 AS mb 
FROM 
    information_schema.tables  
GROUP BY 
    table_schema 
ORDER BY       
    sum(data_length+index_length) DESC;

テーブルのサイズ

mysqlコマンド
SELECT  
    table_name, engine, table_rows AS tbl_rows,
    avg_row_length AS rlen,  
    floor((data_length+index_length)/1024/1024) AS allmb,  #総容量
    floor((data_length)/1024/1024) AS dmb,  #データ容量
    floor((index_length)/1024/1024) AS imb   #インデックス容量
FROM 
    information_schema.tables  
WHERE
    table_schema=database()  
ORDER BY
    (data_length+index_length) DESC;  
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6