Disk-Usage
使用 du 和 tree 命令的累積大小磁碟使用情況
我需要以
/
深度 1 顯示我的根目錄文件累積大小它看起來很容易,但我無法執行它值得樹命令不顯示累積大小
tree --du -h -L 1 . ├── [ 7] bin -> usr/bin ├── [4.0K] boot ├── [ 21K] desktopfs-pkgs.txt ├── [4.2K] dev ├── [ 12K] etc ├── [4.0K] home ├── [ 7] lib -> usr/lib ├── [ 7] lib64 -> usr/lib ├── [ 16K] lost+found ├── [4.0K] media ├── [4.0K] mnt ├── [4.0K] opt ├── [ 0] proc ├── [4.0K] root ├── [4.8K] rootfs-pkgs.txt ├── [ 800] run ├── [ 7] sbin -> usr/bin ├── [ 19] snap -> /var/lib/snapd/snap ├── [4.0K] srv ├── [ 0] sys ├── [ 520] tmp ├── [4.0K] Untitled Folder ├── [4.0K] usr └── [4.0K] var
還有,
du
命令du -h -d 1 / 8,0K /media du: cannot read directory '/sys/kernel/tracing': Permission denied du: cannot read directory '/sys/kernel/debug': Permission denied du: cannot read directory '/sys/fs/pstore': Permission denied du: cannot read directory '/sys/fs/bpf': Permission denied 0 /sys 166G /mnt du: cannot read directory '/run/udisks2': Permission denied du: cannot read directory '/run/wpa_supplicant': Permission denied du: cannot read directory '/run/user/1000/systemd/inaccessible/dir': Permission denied du: cannot read directory '/run/svnserve': Permission denied du: cannot read directory '/run/sudo': Permission denied du: cannot read directory '/run/lightdm': Permission denied du: cannot read directory '/run/lock/lvm': Permission denied du: cannot read directory '/run/systemd/unit-root': Permission denied du: cannot read directory '/run/systemd/inaccessible/dir': Permission denied 1,6M /run du: cannot read directory '/home/max/.cache/yay/wine-stable/pkg': Permission denied du: cannot read directory '/home/max/.cache/yay/gnuradio-git/pkg': Permission denied du: cannot read directory '/home/max/.cache/yay/pamac-classic/pkg': Permission denied du: cannot read directory '/home/max/.cache/yay/wine-stable-next/pkg': Permission denied du: cannot read directory '/home/max/.cache/yay/pamac-aur/pkg': Permission denied du: cannot read directory '/home/max/.cache/paru/clone/qm-dfu-util-git/pkg': Permission denied du: cannot read directory '/home/lost+found': Permission denied 146G /home . . . Goes so on
我只需要 1 個深度,但
du -h -d 1 /
命令顯示權限被拒絕。我怎樣才能忽略它們以獲得我試圖給出的最清晰的視圖root permission
但顯示小錯誤sudo du -h -d 1 / 8,0K /media 0 /sys 166G /mnt du: cannot access '/run/user/1000/gvfs': Permission denied 1,6M /run 146G /home du: cannot access '/proc/12363/task/12363/fd/4': No such file or directory du: cannot access '/proc/12363/task/12363/fdinfo/4': No such file or directory du: cannot access '/proc/12363/fd/3': No such file or directory du: cannot access '/proc/12363/fdinfo/3': No such file or directory 0 /proc 19M /etc 16K /lost+found 0 /dev 49G /usr 41G /var 4,0K /Untitled Folder 9,1M /srv 2,6G /opt 1,8M /root 51M /tmp 98M /boot 403G /
我在網上瀏覽了許多範例,這些命令看起來很棒,但我的終端哪個 Shell: bash 5.1.0 在預設 Manjaro 下看起來有點離完美
在檢查磁碟使用情況時,虛擬文件系統的內容(例如,在我的 GNU/Linux 上:、、、和)
/dev
通常是不相關的。排除它們會使事情變得更容易。/proc``/run``/sys``/tmp
使用
du
,如果您可以只列出掛載的文件系統的內容/
(忽略其他掛載點的內容),則可以執行:sudo du -h -d1 -a -x /
或者,如果您不想使用
-x
(“一個文件系統”)選項:sudo du -h -d1 -a --exclude=/dev --exclude=/proc \ --exclude=/run --exclude=/sys --exclude=/tmp /
(
-a
也使du
顯示正常文件)。雖然
tree
不能限制其輸出的深度,-L
也不能顯示目錄的全深度大小(即包括所有包含的子目錄和文件),但您可以讓它產生格式化的輸出並在之後過濾它。例如,使用 JSON 和jq
:sudo tree --du -a -x -h -J / | jq 'del(.[]?[]?[]?[]?[]?)'
(不幸的是,
tree
的 JSON 輸出往往包含格式錯誤的位,使得該解決方案非常不可靠)。您也可以參考Tracking down where disk space has going on Linux? 如果您對問題中提到的工具以外的工具感興趣。