Tìm file có dung lượng lớn trên linux

Thử tưởng tượng, một ngày đẹp trời, không nắng không gió không mưa, trường học thì đóng cửa, vợ thì bảo ở nhà chăm con, code thì code hoài code mãi vẫn lỗi. Buồn buồn vác linux ra vọc xem sao, tự nhiên muốn xem trong máy có những file nào dung lượng lớn, xóa bớt đi cho đỡ buồn hay cho trống bớt ổ đĩa cũng được. Dưới đây là một đoạn lệnh linux tôi muốn giới thiệu với bạn để nghịch cho đỡ buồn. Công dụng thì khỏi phải nói, đó là tìm file có dung lượng lớn trên linux.

find {directory} -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

1. Tìm file có dung lượng >= 100MB

Tìm tất cả các file có size (dung lượng) >= 100MB từ thư mục root (/) và các thư mục con

sudo find / -type f -size +102400k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Kết quả:

/var/cache/oracle-jdk8-installer/jdk-8u121-linux-x64.tar.gz: 175M
/home/ngockhuong/Downloads/Murach's: 175M
/home/ngockhuong/Downloads/Joel: 351M
/home/ngockhuong/.Genymobile/Genymotion/ova/genymotion_vbox86p_6.0_160825_141918.ova: 292M
/home/ngockhuong/.Genymobile/Genymotion/ova/genymotion_vbox86p_5.1_160825_071239.ova: 248M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 622M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 129M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 533M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 2,8G
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 281M
...

2. Tìm file có dung lượng >= 50MB

Tìm tất cả các file có size (dung lượng) >= 50MB từ thư mục ngockhuong (/home/ngockhuong) và các thư mục con

sudo find /home/ngockhuong -type f -size +51200k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Kết quả:

/home/ngockhuong/Downloads/Murach's: 175M
/home/ngockhuong/Downloads/Joel: 351M
/home/ngockhuong/.AndroidStudio2.2/system/restart/jre/lib/rt.jar: 62M
/home/ngockhuong/.AndroidStudio2.2/system/caches/content.dat.storageData: 56M
/home/ngockhuong/.AndroidStudio2.2/system/index/bytecodeanalysis/bytecodeAnalysis.storage.values: 53M
/home/ngockhuong/.thunderbird/g5pcz40j.default/ImapMail/imap.gmail.com/[Gmail].sbd/T&HqU-t: 58M
/home/ngockhuong/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10-all.zip: 66M
/home/ngockhuong/.Genymobile/Genymotion/ova/genymotion_vbox86p_6.0_160825_141918.ova: 292M
/home/ngockhuong/.Genymobile/Genymotion/ova/genymotion_vbox86p_5.1_160825_071239.ova: 248M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 622M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 129M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 533M
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 2,8G
/home/ngockhuong/.Genymobile/Genymotion/deployed/Google: 281M

3. Tìm file có dung lượng lớn tùy thích

Từ 2 ví dụ trên, bạn biết mình phải chỉnh sửa lệnh ở đâu rồi chứ. Có 2 nơi để sửa lại lệnh:

  • Đường dẫn thư mục muốn tìm, thay phần {directory}
  • Dung lượng file nhỏ nhất cần tìm: +100000k thay thành dung lượng bạn muốn. Cứ lấy 1024 x Số MB tối thiểu. Ví dụ: Tìm file có dung lượng >= 11MB thì sửa thành +11264k
Chú ý: Các lệnh trên đã test chạy ầm ầm trên Ubuntu, Linux Mint và cả Mac OSX.

5 1 vote
Đánh giá bài viết
Nhận thông báo
Thông báo khi có
guest

0 Bình luận
Phản hồi nội tuyến
Xem tất cả các bình luận