【Linux】ファイルを削除しても全然容量が減らないときの対処法

バージョン centos 6.3

df -Th
Filesystem    Type    Size  Used Avail Use% マウント位置
/dev/mapper/yyyyy-lv_root
              ext4     50G   47G  271M 100% /
tmpfs        tmpfs    939M     0  939M   0% /dev/shm
/dev/sda1     ext4    485M   37M  423M   8% /boot
/dev/mapper/xxx_home
              ext4     45G  180M   43G   1% /home
容量の大きいファイルを探す
du / | sort -nr | head -30

1639048002  /hoge/fuga/application.log
163904803   /hoge/fuga/abc.txt
16390432    /hoge/fuga/xyz.txt

psgiで起動したときのlogがどうやら重かったみたい。

ファイル削除
rm /hoge/fuga/application.log

あれ容量の大きいファイルを削除したのに容量減らない

df -Th
Filesystem    Type    Size  Used Avail Use% マウント位置
/dev/mapper/yyyyy-lv_root
              ext4     50G   47G  271M 100% /
tmpfs        tmpfs    939M     0  939M   0% /dev/shm
/dev/sda1     ext4    485M   37M  423M   8% /boot
/dev/mapper/xxx_home
              ext4     45G  180M   43G   1% /home

lsofで使用中のプロセスの調査

lsof | grep .log
rsyslogd   1229      root  cwd   unknown                                        /proc/1229/cwd (readlink: Permission denied)
rsyslogd   1229      root  rtd   unknown                                        /proc/1229/root (readlink: Permissiondenied)
rsyslogd   1229      root  txt   unknown                                        /proc/1229/exe (readlink: Permission denied)
rsyslogd   1229      root NOFD                                                  /proc/1229/fd (opendir: Permission denied)
/www  12341  test    2w      REG              253,0 28740161536 2755540   /hoge/fuga/application.log (deleted)
/www  12341  test    5w      REG              253,0    31453184 2771021      /hoge/fuga/application.log (deleted)
/www  12341  test    6w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)
/www  12341  test    7w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)
/www  12341  test   10w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)
/www  12341  test   13w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)
/www  12341  test   14w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)
/www  12341  test   15w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)
/www  12341  test   16w      REG              253,0  5201436672 2771023 /hoge/fuga/application.log (deleted)

どうやら12341で使用中だったみたい

対象のプロセス削除
kill -9 12341

開放されたみたいで空き容量が増えた

df -Th
Filesystem    Type    Size  Used Avail Use% マウント位置
/dev/mapper/yyyyy-lv_root
              ext4     50G   14G  34G 29% /
tmpfs        tmpfs    939M     0  939M   0% /dev/shm
/dev/sda1     ext4    485M   37M  423M   8% /boot
/dev/mapper/xxx_home
              ext4     45G  180M   43G   1% /home

良かった

【Linux】マシンスペックを調べるコマンド

CPUの情報表示

cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
stepping        : 3
cpu MHz         : 0.000
cache size      : 8192 KB
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc up rep_good xtopology nonstop_tsc pni pclmulqdq monitor ssse3 cx16 sse4_1 sse4_2 movbepopcnt aes rdrand lahf_lm abm
bogomips        : 8159.23
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

メモリ情報表示

cat /proc/meminfo
MemTotal:         502212 kB
MemFree:           55072 kB
Buffers:           89296 kB
Cached:           127412 kB
SwapCached:          764 kB
Active:           167568 kB
Inactive:         172168 kB
Active(anon):      44348 kB
Inactive(anon):    79068 kB
Active(file):     123220 kB
Inactive(file):    93100 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       3112944 kB
SwapFree:        3110908 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        122532 kB
Mapped:            19592 kB
Shmem:               388 kB
Slab:              83308 kB
SReclaimable:      58772 kB
SUnreclaim:        24536 kB
KernelStack:        1648 kB
PageTables:        11796 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3364048 kB
Committed_AS:     641032 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       20984 kB
VmallocChunk:   34359708152 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:        8128 kB
DirectMap2M:      516096 kB

MySQL 操作

接続

/usr/bin/mysql -hlocalhost -utest -ptestp test

全てのテーブルとデータをファイルに出力

/usr/bin/mysql -hlocalhost -utest -ptestp test>~/all.dump

対象のテーブルcreate文をファイルに出力

/usr/bin/mysql -hlocalhost -utest -ptestp test>~/all.dump テーブル名 -d >~/テーブル名_create.dump

対象テーブルデータをファイルに出力

/usr/bin/mysql -hlocalhost -utest -ptestp test テーブル名 -t >~/テーブル名_data.dump

vagrant up --provision時のエラー

環境

ホストマシン

winodows7 Professional

メモリ4G

32ビット

原因

vagrant haltしないでwindowsのマシンをシャットダウンしてしまったせいかもしれない。

エラー内容

Bringing machine 'default' up with 'virtualbox' provider...
Your VM has become "inaccessible." Unfortunately, this is a critical error
with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBo
x
and clear out your inaccessible virtual machines or find a way to fix
them.

対応方法

VirtualBoxマネージャーを開いてエラー内容を確認

どうやら C:Users{ユーザ名}VirtualBox VMs{vm名}の中に入っている、 {vm名}.vbox-tmpの拡張子を{vm名}.vboxに書き換えたらうまく起動できた。

Markdownで取り消し線つけたい場合

下記の様に入力する!!

~~ああああああああああああああ~~

変換後

ああああああああああああああ

git diff 実行時にファイル全体を表示させたいとき

git diff -U9999

Uは行数を表示するオプション.例えば10を設定すると差分行まわりで10行が出力される.ファイル内容について全行出力したいため大きな値9999を指定

perlで連続する同じ文字列を探す方法

同一文字が3回以上連続する場合

#!/usr/bin/perl
use strict;
use warnings;

my $test = 'xyz123aaa';
#(.)は任意の1文字
#\1は正規表現内でマッチした文字 この場合任意の1文字
#{2,}2回以上連続した場合
if ($test =~ /(.)\1{2,}/){
    print "$test\n";
}

perlって便利