1. 程式人生 > >【空間釋放】解決Linux下rm操作不釋放空間的問題

【空間釋放】解決Linux下rm操作不釋放空間的問題

最近在開發的過程中,不小心把螢幕回顯的輸出定向到nohup.out裡去了,導致週末過完回來一看,我的天被打滿了……

然後趕緊刪掉這104個G的檔案,看看空間還給我沒——

啊咧?

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda1              20G  3.4G   16G  18% /
/dev/vdb              155G  148G     0 100% /home
然後我趕緊看看這個資料夾大小——

啊咧?

du -h
176K    ./goose/python-goose/dist
96K     ./goose/python-goose/goose/resources/text
8.0K    ./goose/python-goose/goose/resources/images
108K    ./goose/python-goose/goose/resources
24K     ./goose/python-goose/goose/utils
84K     ./goose/python-goose/goose/extractors
304K    ./goose/python-goose/goose
36K     ./goose/python-goose/goose_extractor.egg-info
4.0K    ./goose/python-goose/build/bdist.linux-x86_64
96K     ./goose/python-goose/build/lib/goose/resources/text
8.0K    ./goose/python-goose/build/lib/goose/resources/images
108K    ./goose/python-goose/build/lib/goose/resources
24K     ./goose/python-goose/build/lib/goose/utils
84K     ./goose/python-goose/build/lib/goose/extractors
300K    ./goose/python-goose/build/lib/goose
68K     ./goose/python-goose/build/lib/tests/extractors
96K     ./goose/python-goose/build/lib/tests
400K    ./goose/python-goose/build/lib
408K    ./goose/python-goose/build
44K     ./goose/python-goose/.git/hooks
8.0K    ./goose/python-goose/.git/logs/refs/remotes/origin
12K     ./goose/python-goose/.git/logs/refs/remotes
8.0K    ./goose/python-goose/.git/logs/refs/heads
24K     ./goose/python-goose/.git/logs/refs
32K     ./goose/python-goose/.git/logs
8.0K    ./goose/python-goose/.git/info
2.0M    ./goose/python-goose/.git/objects/pack
4.0K    ./goose/python-goose/.git/objects/info
2.0M    ./goose/python-goose/.git/objects
4.0K    ./goose/python-goose/.git/refs/tags
8.0K    ./goose/python-goose/.git/refs/remotes/origin
12K     ./goose/python-goose/.git/refs/remotes
8.0K    ./goose/python-goose/.git/refs/heads
28K     ./goose/python-goose/.git/refs
4.0K    ./goose/python-goose/.git/branches
2.2M    ./goose/python-goose/.git
68K     ./goose/python-goose/tests/extractors
8.0K    ./goose/python-goose/tests/data/parser
292K    ./goose/python-goose/tests/data/extractors/tags
12K     ./goose/python-goose/tests/data/extractors/tweets
4.0M    ./goose/python-goose/tests/data/extractors/content
12K     ./goose/python-goose/tests/data/extractors/opengraph
32K     ./goose/python-goose/tests/data/extractors/videos
112K    ./goose/python-goose/tests/data/extractors/images/test_basic_image
12K     ./goose/python-goose/tests/data/extractors/images/test_known_image_name_parent
12K     ./goose/python-goose/tests/data/extractors/images/test_known_image_css_parent_class
12K     ./goose/python-goose/tests/data/extractors/images/test_known_image_css_parent_id
12K     ./goose/python-goose/tests/data/extractors/images/test_opengraph_tag
12K     ./goose/python-goose/tests/data/extractors/images/test_known_image_empty_src
12K     ./goose/python-goose/tests/data/extractors/images/test_known_image_css_id
12K     ./goose/python-goose/tests/data/extractors/images/test_known_image_css_class
200K    ./goose/python-goose/tests/data/extractors/images
36K     ./goose/python-goose/tests/data/extractors/publishdate
12K     ./goose/python-goose/tests/data/extractors/links
20K     ./goose/python-goose/tests/data/extractors/title
12K     ./goose/python-goose/tests/data/extractors/authors
4.6M    ./goose/python-goose/tests/data/extractors
4.6M    ./goose/python-goose/tests/data
4.7M    ./goose/python-goose/tests
7.8M    ./goose/python-goose
7.8M    ./goose
12K     ./nginx-push-stream-module/nginx-1.2.0/man
24K     ./nginx-push-stream-module/nginx-1.2.0/contrib/unicode2nginx
36K     ./nginx-push-stream-module/nginx-1.2.0/contrib
4.0K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/mail
4.0K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/http/modules/perl
2.7M    ./nginx-push-stream-module/nginx-1.2.0/objs/src/http/modules
4.4M    ./nginx-push-stream-module/nginx-1.2.0/objs/src/http
1000K   ./nginx-push-stream-module/nginx-1.2.0/objs/src/core
484K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/os/unix
4.0K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/os/win32
492K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/os
48K     ./nginx-push-stream-module/nginx-1.2.0/objs/src/event/modules
288K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/event
4.0K    ./nginx-push-stream-module/nginx-1.2.0/objs/src/misc
6.1M    ./nginx-push-stream-module/nginx-1.2.0/objs/src
4.0K    ./nginx-push-stream-module/nginx-1.2.0/objs/addon/src
8.0K    ./nginx-push-stream-module/nginx-1.2.0/objs/addon
6.2M    ./nginx-push-stream-module/nginx-1.2.0/objs
28K     ./nginx-push-stream-module/nginx-1.2.0/auto/os
44K     ./nginx-push-stream-module/nginx-1.2.0/auto/cc
12K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/libatomic
8.0K    ./nginx-push-stream-module/nginx-1.2.0/auto/lib/libxslt
24K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/sha1
12K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/perl
8.0K    ./nginx-push-stream-module/nginx-1.2.0/auto/lib/libgd
8.0K    ./nginx-push-stream-module/nginx-1.2.0/auto/lib/geoip
28K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/zlib
28K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/pcre
8.0K    ./nginx-push-stream-module/nginx-1.2.0/auto/lib/google-perftools
20K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/openssl
24K     ./nginx-push-stream-module/nginx-1.2.0/auto/lib/md5
196K    ./nginx-push-stream-module/nginx-1.2.0/auto/lib
20K     ./nginx-push-stream-module/nginx-1.2.0/auto/types
432K    ./nginx-push-stream-module/nginx-1.2.0/auto
40K     ./nginx-push-stream-module/nginx-1.2.0/conf
280K    ./nginx-push-stream-module/nginx-1.2.0/src/mail
64K     ./nginx-push-stream-module/nginx-1.2.0/src/http/modules/perl
1.3M    ./nginx-push-stream-module/nginx-1.2.0/src/http/modules
2.1M    ./nginx-push-stream-module/nginx-1.2.0/src/http
668K    ./nginx-push-stream-module/nginx-1.2.0/src/core
420K    ./nginx-push-stream-module/nginx-1.2.0/src/os/unix
424K    ./nginx-push-stream-module/nginx-1.2.0/src/os
140K    ./nginx-push-stream-module/nginx-1.2.0/src/event/modules
348K    ./nginx-push-stream-module/nginx-1.2.0/src/event
12K     ./nginx-push-stream-module/nginx-1.2.0/src/misc
3.8M    ./nginx-push-stream-module/nginx-1.2.0/src
12K     ./nginx-push-stream-module/nginx-1.2.0/html
11M     ./nginx-push-stream-module/nginx-1.2.0
272K    ./nginx-push-stream-module/nginx-push-stream-module/src
92K     ./nginx-push-stream-module/nginx-push-stream-module/include
44K     ./nginx-push-stream-module/nginx-push-stream-module/.git/hooks
8.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/logs/refs/remotes/origin
12K     ./nginx-push-stream-module/nginx-push-stream-module/.git/logs/refs/remotes
8.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/logs/refs/heads
24K     ./nginx-push-stream-module/nginx-push-stream-module/.git/logs/refs
32K     ./nginx-push-stream-module/nginx-push-stream-module/.git/logs
8.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/info
2.1M    ./nginx-push-stream-module/nginx-push-stream-module/.git/objects/pack
4.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/objects/info
2.1M    ./nginx-push-stream-module/nginx-push-stream-module/.git/objects
4.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/refs/tags
8.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/refs/remotes/origin
12K     ./nginx-push-stream-module/nginx-push-stream-module/.git/refs/remotes
8.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/refs/heads
28K     ./nginx-push-stream-module/nginx-push-stream-module/.git/refs
4.0K    ./nginx-push-stream-module/nginx-push-stream-module/.git/branches
2.3M    ./nginx-push-stream-module/nginx-push-stream-module/.git
60K     ./nginx-push-stream-module/nginx-push-stream-module/docs/examples
36K     ./nginx-push-stream-module/nginx-push-stream-module/docs/directives
112K    ./nginx-push-stream-module/nginx-push-stream-module/docs
20K     ./nginx-push-stream-module/nginx-push-stream-module/misc/examples
116K    ./nginx-push-stream-module/nginx-push-stream-module/misc/js
48K     ./nginx-push-stream-module/nginx-push-stream-module/misc/tools
72K     ./nginx-push-stream-module/nginx-push-stream-module/misc/spec/publisher
168K    ./nginx-push-stream-module/nginx-push-stream-module/misc/spec/subscriber
8.0K    ./nginx-push-stream-module/nginx-push-stream-module/misc/spec/javascripts/helpers
12K     ./nginx-push-stream-module/nginx-push-stream-module/misc/spec/javascripts/support
72K     ./nginx-push-stream-module/nginx-push-stream-module/misc/spec/javascripts
124K    ./nginx-push-stream-module/nginx-push-stream-module/misc/spec/mix
456K    ./nginx-push-stream-module/nginx-push-stream-module/misc/spec
676K    ./nginx-push-stream-module/nginx-push-stream-module/misc
3.5M    ./nginx-push-stream-module/nginx-push-stream-module
16M     ./nginx-push-stream-module
44K     ./word2vec/.git/hooks
8.0K    ./word2vec/.git/logs/refs/remotes/origin
12K     ./word2vec/.git/logs/refs/remotes
8.0K    ./word2vec/.git/logs/refs/heads
24K     ./word2vec/.git/logs/refs
32K     ./word2vec/.git/logs
8.0K    ./word2vec/.git/info
132K    ./word2vec/.git/objects/pack
4.0K    ./word2vec/.git/objects/info
140K    ./word2vec/.git/objects
4.0K    ./word2vec/.git/refs/tags
8.0K    ./word2vec/.git/refs/remotes/origin
12K     ./word2vec/.git/refs/remotes
8.0K    ./word2vec/.git/refs/heads
28K     ./word2vec/.git/refs
276K    ./word2vec/.git
8.9G    ./word2vec
8.9G    .

沒錯啊,總計8.9G,那100多G的檔案確實我已經刪了啊……再看一下磁碟空間:

100%……

這這這……我已經刪了啊

趕緊查一查解決方法——

好多地方都說是殺程序,於是top,kill了一下……居然真的就把空間還給我了……

 df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda1              20G  3.4G   16G  18% /
/dev/vdb              155G   49G   99G  33% /home


關於網上的解決方案和解釋,大概如下——

因為被刪除的檔案在刪除的時侯還是程序在操作(開啟、訪問等)的緣故,rm只完成了在磁碟上檔案實體的釋放,而類似free list結構中相應的檔案系統因程序的操作相應的inode並未釋放。

解決的方法:這樣的問題解決起來也很簡單,找到操作的程序,kill掉就可以了,可是找到操作的程序恰恰是本問題的難點和關鍵。這樣的問題也可以通過重啟機器和nmount/mount檔案系統這樣的方式解決,但這樣的方法我是不提倡的,小小的問題就重啟機器,小題大做。

linux及solaris可以這樣做: 
a、下載一個lsof軟體裝上,google上可以搜到 
b、找到正在用被刪檔案的程序 
lsof | grep deleted 
c、kill掉相應的程序空間就釋放了