查找目录内的所有文件

查找目录内的所有文件

好的,此远程计算机上的系统磁盘已满:

$ df -h
Filesystem           Size  Used Avail Use% Mounted on
udev                 7,8G     0  7,8G   0% /dev
tmpfs                1,6G  3,3M  1,6G   1% /run
/dev/sdd1            117G  115G     0 100% /

但当我列出它的内容时:

du -sh ./* | sort -h
4,0K    ./Documents
4,0K    ./Music
4,0K    ./Pictures
4,0K    ./Public
4,0K    ./rclone.conf
4,0K    ./Templates
4,0K    ./Videos
8,0K    ./Desktop
12K     ./examples.desktop
24K     ./file.txt
1,5M    ./home
5,8M    ./snap
13M     ./Downloads

如何查找占用了这115GB的内容?

PS:我已经做了sudo apt autoremove

备注:

sudo du -a . | sort -n -r | head -n 20
696668  .
364008  ./.cache
258880  ./.pyenv
250528  ./.pyenv/versions
250524  ./.pyenv/versions/3.8.5
246128  ./.cache/pip
239544  ./.cache/pip/http
231148  ./.pyenv/versions/3.8.5/lib
197244  ./.pyenv/versions/3.8.5/lib/python3.8
100336  ./.cache/mozilla
100332  ./.cache/mozilla/firefox
100328  ./.cache/mozilla/firefox/b38hqcj0.default
79088   ./.cache/mozilla/firefox/b38hqcj0.default/cache2
78984   ./.cache/mozilla/firefox/b38hqcj0.default/cache2/entries
65020   ./.pyenv/versions/3.8.5/lib/python3.8/test
51684   ./.cache/pip/http/5
49216   ./.cache/pip/http/5/1
48868   ./.cache/pip/http/5/1/d
48864   ./.cache/pip/http/5/1/d/8
48860   ./.cache/pip/http/5/1/d/8/2

# 编辑 Ray 的评论:

:~# du -sh * | sort -h
4,0K    Documents
4,0K    Music
4,0K    Pictures
4,0K    Public
4,0K    rclone.conf
4,0K    Templates
4,0K    Videos
8,0K    Desktop
12K     examples.desktop
24K     file.txt
1,5M    home
5,8M    snap
13M     Downloads

#编辑:@sancho.s 的想法:

sudo du / -h --max-depth=1 | sort --human-numeric-sort 
[sudo] password for install: 
du: cannot access '/proc/30550/task/30550/fd/3': No such file or directory
du: cannot access '/proc/30550/task/30550/fdinfo/3': No such file or directory
du: cannot access '/proc/30550/fd/4': No such file or directory
du: cannot access '/proc/30550/fdinfo/4': No such file or directory
0       /dev
0       /proc
0       /sys
4,0K    /cdrom
4,0K    /lib64
4,0K    /media
4,0K    /srv
8,0K    /samba
16K     /lost+found
220K    /tmp
3,3M    /run
7,3M    /root
12M     /sbin
13M     /bin
15M     /etc
112M    /boot
930M    /lib
1,1G    /home
1,4G    /opt
3,4G    /var
4,3G    /usr
5,1G    /snap
4,2T    /
4,2T    /mnt


$ uname -a
Linux PC-IT-UBUIEX 4.15.0-144-generic #148-Ubuntu SMP Sat May 8 02:33:43 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
install@PC-IT-UBUIEX:~$ ls -al /
total 2098716
drwxr-xr-x  25 root root             4096 čen 25 06:17 .
drwxr-xr-x  25 root root             4096 čen 25 06:17 ..
drwxr-xr-x   2 root root             4096 čen 18 06:47 bin
drwxr-xr-x   3 root root             4096 čen 26 06:30 boot
drwxrwxr-x   2 root root             4096 zář  5  2018 cdrom
drwxr-xr-x  20 root root             4520 čec  6 12:39 dev
-rw-r--r--   1 root root          1479017 zář 29  2018 Documents
drwxr-xr-x 148 root root            12288 čec  2 12:20 etc
drwxr-xr-x   9 root root             4096 čec  2 17:29 home
lrwxrwxrwx   1 root root               34 čen 25 06:17 initrd.img -> boot/initrd.img-4.15.0-147-generic
lrwxrwxrwx   1 root root               34 čen 25 06:17 initrd.img.old -> boot/initrd.img-4.15.0-144-generic
drwxr-xr-x  21 root root             4096 zář  5  2018 lib
drwxr-xr-x   2 root root             4096 čec  8  2020 lib64
drwx------   2 root root            16384 zář  5  2018 lost+found
drwxr-xr-x   2 root root             4096 čen  8 13:37 media
drwxr-xr-x   6 root root             4096 čen 18 10:45 mnt
drwxr-xr-x   5 root root             4096 bře  9 18:39 opt
dr-xr-xr-x 262 root root                0 čen 24 05:39 proc
drwx------   7 root root             4096 čec  2 13:13 root
drwxr-xr-x  33 root root             1120 čec 10 10:09 run
drwxr-xr-x   3 root sambashare       4096 zář 24  2019 samba
drwxr-xr-x   2 root root            12288 čen  5 06:30 sbin
drwxr-xr-x  17 root root             4096 čec  2 14:15 snap
drwxr-xr-x   2 root root             4096 čec 25  2018 srv
-rw-------   1 root root       2147483648 zář  5  2018 swapfile
dr-xr-xr-x  13 root root                0 čen 24 05:39 sys
drwxrwxrwt  18 root root             4096 čec 10 10:09 tmp
drwxr-xr-x  11 root root             4096 zář  3  2019 usr
drwxr-xr-x  14 root root             4096 čec 25  2018 var
lrwxrwxrwx   1 root root               31 čen 25 06:17 vmlinuz -> boot/vmlinuz-4.15.0-147-generic
lrwxrwxrwx   1 root root               31 čen 25 06:17 vmlinuz.old -> boot/vmlinuz-4.15.0-144-generic

/mnt/ 是挂载的磁盘,不是系统磁盘(对吗?)。所以除了那个之外,我没有看到任何总计为 115G 的东西……

~# du /mnt -h --max-depth=1 | sort --human-numeric-sort 
306G    /mnt/sdb
467G    /mnt/sda
1,7T    /mnt/sdc
1,7T    /mnt/sdd
4,2T    /mnt

# ls -al /mnt
total 20
drwxr-xr-x  6 root root 4096 čen 18 10:45 .
drwxr-xr-x 25 root root 4096 čen 25 06:17 ..
drwxrwxrwx  5 6687 6687 4096 čen 16 23:44 sda
drwxr-xr-x  3 root root 4096 čen 19 17:50 sdb
drwxrwxrwx 16 root root 4096 čec  9 14:43 sdc
drwxr-xr-x  2 root root    0 čen 22 08:50 sdd


:/usr/local/bin$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0    7:0    0   548K  1 loop /snap/gnome-logs/106
loop1    7:1    0  99,4M  1 loop /snap/core/11187
loop2    7:2    0  55,4M  1 loop /snap/core18/2066
loop5    7:5    0   219M  1 loop /snap/gnome-3-34-1804/72
loop7    7:7    0   704K  1 loop /snap/gnome-characters/726
loop8    7:8    0 136,2M  1 loop /snap/b2/25
loop9    7:9    0   6,3M  1 loop /snap/rclone/466
loop10   7:10   0  61,7M  1 loop /snap/core20/1026
loop12   7:12   0  65,1M  1 loop /snap/gtk-common-themes/1515
loop14   7:14   0   2,5M  1 loop /snap/gnome-calculator/884
loop15   7:15   0 164,8M  1 loop /snap/gnome-3-28-1804/161
loop20   7:20   0 140,7M  1 loop /snap/gnome-3-26-1604/104
loop22   7:22   0  55,5M  1 loop /snap/core18/2074
loop23   7:23   0  99,4M  1 loop /snap/core/11316
loop25   7:25   0 243,9M  1 loop /snap/gnome-3-38-2004/39
loop26   7:26   0   2,5M  1 loop /snap/gnome-system-monitor/163
sda      8:0    0 931,5G  0 disk 
└─sda1   8:1    0 931,5G  0 part /mnt/sda
sdb      8:16   0 931,5G  0 disk 
└─sdb1   8:17   0 931,5G  0 part /mnt/sdb
sdc      8:32   0   1,8T  0 disk /mnt/sdc
sdd      8:48   0 119,2G  0 disk 
└─sdd1   8:49   0 119,2G  0 part /



df -h
Filesystem           Size  Used Avail Use% Mounted on
udev                 7,8G     0  7,8G   0% /dev
tmpfs                1,6G  3,3M  1,6G   1% /run
/dev/sdd1            117G  115G     0 100% /
tmpfs                7,8G     0  7,8G   0% /dev/shm
tmpfs                5,0M  4,0K  5,0M   1% /run/lock
tmpfs                7,8G     0  7,8G   0% /sys/fs/cgroup
/dev/loop2            56M   56M     0 100% /snap/core18/2066
/dev/loop1           100M  100M     0 100% /snap/core/11187
/dev/loop5           219M  219M     0 100% /snap/gnome-3-34-1804/72
/dev/loop8           137M  137M     0 100% /snap/b2/25
/dev/loop9           6,4M  6,4M     0 100% /snap/rclone/466
/dev/loop12           66M   66M     0 100% /snap/gtk-common-themes/1515
/dev/loop14          2,5M  2,5M     0 100% /snap/gnome-calculator/884
/dev/loop22           56M   56M     0 100% /snap/core18/2074
/dev/sda1            917G  467G  404G  54% /mnt/sda
/dev/sdb1            916G  307G  564G  36% /mnt/sdb
/dev/sdc             1,8T  1,7T   40G  98% /mnt/sdc
tmpfs                1,6G   16K  1,6G   1% /run/user/121
/dev/loop23          100M  100M     0 100% /snap/core/11316
/dev/loop20          141M  141M     0 100% /snap/gnome-3-26-1604/104
tmpfs                1,6G     0  1,6G   0% /run/user/1000
//192.168.50.2/Algo   16T  1,8T   15T  12% /mnt/sdd
/dev/loop10           62M   62M     0 100% /snap/core20/1026
/dev/loop25          244M  244M     0 100% /snap/gnome-3-38-2004/39
/dev/loop0           640K  640K     0 100% /snap/gnome-logs/106
/dev/loop7           768K  768K     0 100% /snap/gnome-characters/726
/dev/loop26          2,5M  2,5M     0 100% /snap/gnome-system-monitor/163
/dev/loop15          165M  165M     0 100% /snap/gnome-3-28-1804/161

@HuHa的建议:

wget https://github.com/shundhammer/qdirstat/raw/master/scripts/qdirstat-cache-writer
--2021-07-10 10:18:34--  https://github.com/shundhammer/qdirstat/raw/master/scripts/qdirstat-cache-writer
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/shundhammer/qdirstat/master/scripts/qdirstat-cache-writer [following]
--2021-07-10 10:18:34--  https://raw.githubusercontent.com/shundhammer/qdirstat/master/scripts/qdirstat-cache-writer
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12542 (12K) [text/plain]
Saving to: ‘qdirstat-cache-writer’

qdirstat-cache-writer                                 100%[=======================================================================================================================>]  12,25K  --.-KB/s    in 0s      

2021-07-10 10:18:34 (60,6 MB/s) - ‘qdirstat-cache-writer’ saved [12542/12542]

sda 有很多空间:

root@PC-IT-UBUIEX:/usr/local/bin# sudo qdirstat-cache-writer / /mnt/sda/myserver-root.cache.gz
sudo: qdirstat-cache-writer: command not found

答案1

执行

sudo du / -h --max-depth=1 | sort --human-numeric-sort 

您应该可以看到那里的所有内容。从您发布的内容来看,似乎文件本身占用了大量空间/,这很奇怪。

请同时发布输出

uname -a
sudo ls -al /
sudo du /mnt -h --max-depth=1 | sort --human-numeric-sort 
sudo ls -al /mnt
lsblk

笔记:

  1. df不需要sudo

答案2

你可以使用下面的命令找到大文件

find / -type f -exec du -h {} + | sort -hr | head -20

1-find

查找目录内的所有文件

find / -type f 此命令只是查找目录中的所有文件(不是目录)。

2 –exec du -h {} +

查找所有文件,然后获取其可读大小

find / -type f -exec du -h {} + 现在,对于找到的每个文件,–exec 命令将执行命令 du -h,该命令以人性化的方式打印每个文件的大小(例如 2.4M)。有关更多信息

{} 要求 du 命令将 find 命令的结果作为输入 + 号要求 du 命令一次处理所有文件(这会使速度更快) 3 –| sort -hr

查找所有文件,然后获取其可读大小,然后按最大文件排序

find / -type f -exec du -h {} + | sort -hr | 符号是 Linux 管道,它将上一个命令(直到 du -h {} +)的输出重定向到新命令,即 sort。因此,您现在实际上是按人类可读的大小(-h)以相反的顺序(-r)对所有找到的文件(及其人类可读的大小)进行排序。

3 –| head -20

查找所有文件,然后获取其可读大小,然后按最大文件排序,最后仅打印前 20 个

find / -type f -exec du -h {} + | sort -hr | head -20

相关内容