linux常用disk磁碟操作命令整理_unix linux

來源:互聯網
上載者:User
複製代碼 代碼如下:

#按照目錄大小排序戰士最前面15個目錄或者檔案
du -xB M --max-depth=2 /var | sort -rn | head -n 15

#列出當前所有子目錄的檔案大小
du -h --max-depth=1

#列出當前檔案或者目錄最大的10個
du -s * | sort -n | tail

#按照目錄大小從大到小排序
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'

#列出path這個目錄的檔案樹
du -h /path | sort -h

#每隔60s監控對應目錄的檔案大小變化
watch -n60 du /var/log/messages


#遞迴刪除目前的目錄下所有子目錄中的.svn目錄
find . -type d -name '.svn' -print0 | xargs -0 rm -rdf

#列出當前磁碟的使用方式
df -P | column -t

#監控磁碟的使用方式
watch -d -n 5 df

#列出當前inode的使用方式
df -i <partition>

#按照每個磁碟使用量從高到低排序
df -h | grep -v ^none | ( read header ; echo "$header" ; sort -rn -k 5)


#查看物理磁碟的使用方式
df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"

#查看當前所有磁碟的大小和使用量
df -H

#查看所有分區使用方式
fdisk -l /dev/sda

# 顯示系統所有的分區或給定的分區
fdisk -l
# 顯示時,顯示的是扇區數不是柱面數
fdisk -u
# 顯示指定partition的block數
fdisk -s partition

#查看磁碟的讀寫容量
iostat -m -d /dev/sda1

#測試磁碟的讀寫速度
hdparm -t /dev/sda

#查看某個檔案的所有連結
find -L / -samefile /path/to/file -exec ls -ld {} +

#查看最大的5個檔案
find . -type f -exec ls -s {} \; | sort -n -r | head -5

#查看365天前的檔案並刪除
find ./ -type f -mtime +365 -exec rm -f {} \;

#查看大於100M的檔案
find . -type f -size +100M

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.