------- [环境] -------
虚拟机,centos 7.6
kernel 升级到了最新 kernel.x86_64.0.3.10.0-957.10.1.el7
find 版本最新 findutils-4.5.11-6.el7.x86_64
QQ 群号=183173532
名称=powershell 交流群
群内创作文章,著作权所有者为群
------- [问题从这里开始] -------
我想,用 powershell 统计,系统最大的 10 个文件。
------- [ linux 的 powershell 命令 1,返回的结果] -------
PS /root> Get-ChildItem / -file -Recurse | Sort-Object length -Descending -top 10 |Select-Object {$_.length / 1mb},fullname
$_.length / 1mb FullName
--------------- --------
134217726.007812 /proc/kcore
101.161056518555 /usr/lib/locale/locale-archive
77.8723373413086 /usr/bin/dockerd-ce
65.3838729858398 /usr/bin/docker
63.01171875 /var/lib/rpm/Packages
51.1564149856567 /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
42.2908325195312 /usr/bin/containerd
29.62109375 /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
28.40234375 /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
27.015625 /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
------- [ linux 的 powershell 命令 2,返回的结果] -------
du -sh (Get-ChildItem / -file -Recurse | Sort-Object length -Descending -top 10 ).fullname
0 /proc/kcore
102M /usr/lib/locale/locale-archive
78M /usr/bin/dockerd-ce
66M /usr/bin/docker
64M /var/lib/rpm/Packages
52M /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
43M /usr/bin/containerd
30M /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29M /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28M /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
我的想法:
咦?怎么变 0 了?我还是用 [正宗 linux 命令] 试试吧。
------- [ linux 的 find 命令 1,返回的结果] -------
find / -type f -exec du -sh {} + | sort -rh | head -n 10
du: 无法访问"/proc/3933/task/3933/fdinfo/6": 没有那个文件或目录
du: 无法访问"/proc/3933/fdinfo/6": 没有那个文件或目录
102M /usr/lib/locale/locale-archive
78M /usr/bin/dockerd-ce
66M /usr/bin/docker
64M /var/lib/rpm/Packages
52M /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
43M /usr/bin/containerd
30M /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29M /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28M /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
27M /opt/microsoft/powershell/6-preview/System.Management.Automation.dll
------- [ linux 的 find 命令 2,返回的结果] -------
find / -type f -print0 | xargs -0 du -h | sort -rh | head -n 10
du: 无法访问"/proc/4157/task/4157/fdinfo/6": 没有那个文件或目录
102M /usr/lib/locale/locale-archive
78M /usr/bin/dockerd-ce
66M /usr/bin/docker
64M /var/lib/rpm/Packages
52M /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
43M /usr/bin/containerd
30M /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29M /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28M /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
27M /opt/microsoft/powershell/6-preview/System.Management.Automation.dll
------- [ linux 的 find 命令 3,返回的结果] -------
find / -type f -ls | sort -k 7 -r -n | head -10 | column -t | awk '{print $7,$11}'
find: ‘/proc/4267/task/4267/fdinfo/6 ’: 没有那个文件或目录
find: ‘/proc/4267/fdinfo/5 ’: 没有那个文件或目录
140737486266368 /proc/kcore
106075056 /usr/lib/locale/locale-archive
81655064 /usr/bin/dockerd-ce
68559960 /usr/bin/docker
66072576 /var/lib/rpm/Packages
53641389 /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
44345152 /usr/bin/containerd
31059968 /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29782016 /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28327936 /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
------- [我的疑问] -------
问 1:linux 上所有都是文件么?
是的话,find,du 为什么会报那些错?谁来答答?
问 2:/proc/kcore 是文件么?
测试代码:
root@centos76 ~]#ls -l
-r--------. 1 root root 140737486266368 3 月 20 10:57 /proc/kcore
问:find 不加 [-print0 ] 参数后,能算 [最大 10 个文件] 么?
答:不行。
欢迎帮忙测试,下面的命令:
find / -type f | xargs -0 du -h | sort -rh | head -n 10
或
find / -type f | xargs du -h | sort -rh | head -n 10
问:加上 [-print0 ] 参数后,返回消失了,这是 find 的 bug 么?
测试代码:
[root@centos76 ~]# find /proc -name 'kc*' -type f
/proc/kcore
/proc/kcore[root@centos76 ~]# find /proc -name 'kc*' -type f -print0
返回空,即无返回
问: [ find / -type f -exec du -sh {}] 也有丢文件的 bug,对么?
答:
应该是 du 的问题。
测试代码:
find /proc -name 'kc*' -type f
/proc/kcore
find /proc -name 'kc*' -type f -exec du -sh {} +
0 /proc/kcore
------- [结论] -------
我认为:
[ linux 的 powershell 命令 1,返回的结果]
[ linux 的 find 命令 3,返回的结果]
靠谱点。
虽然 [/proc/kcore ] 返回的结果我并不需要。
当然,我也认为,没占磁盘,du 不应该返回。
powershell 那两个返回都是可以的,find 的返回就不乐观了。
虚拟机,centos 7.6
kernel 升级到了最新 kernel.x86_64.0.3.10.0-957.10.1.el7
find 版本最新 findutils-4.5.11-6.el7.x86_64
QQ 群号=183173532
名称=powershell 交流群
群内创作文章,著作权所有者为群
------- [问题从这里开始] -------
我想,用 powershell 统计,系统最大的 10 个文件。
------- [ linux 的 powershell 命令 1,返回的结果] -------
PS /root> Get-ChildItem / -file -Recurse | Sort-Object length -Descending -top 10 |Select-Object {$_.length / 1mb},fullname
$_.length / 1mb FullName
--------------- --------
134217726.007812 /proc/kcore
101.161056518555 /usr/lib/locale/locale-archive
77.8723373413086 /usr/bin/dockerd-ce
65.3838729858398 /usr/bin/docker
63.01171875 /var/lib/rpm/Packages
51.1564149856567 /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
42.2908325195312 /usr/bin/containerd
29.62109375 /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
28.40234375 /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
27.015625 /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
------- [ linux 的 powershell 命令 2,返回的结果] -------
du -sh (Get-ChildItem / -file -Recurse | Sort-Object length -Descending -top 10 ).fullname
0 /proc/kcore
102M /usr/lib/locale/locale-archive
78M /usr/bin/dockerd-ce
66M /usr/bin/docker
64M /var/lib/rpm/Packages
52M /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
43M /usr/bin/containerd
30M /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29M /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28M /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
我的想法:
咦?怎么变 0 了?我还是用 [正宗 linux 命令] 试试吧。
------- [ linux 的 find 命令 1,返回的结果] -------
find / -type f -exec du -sh {} + | sort -rh | head -n 10
du: 无法访问"/proc/3933/task/3933/fdinfo/6": 没有那个文件或目录
du: 无法访问"/proc/3933/fdinfo/6": 没有那个文件或目录
102M /usr/lib/locale/locale-archive
78M /usr/bin/dockerd-ce
66M /usr/bin/docker
64M /var/lib/rpm/Packages
52M /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
43M /usr/bin/containerd
30M /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29M /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28M /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
27M /opt/microsoft/powershell/6-preview/System.Management.Automation.dll
------- [ linux 的 find 命令 2,返回的结果] -------
find / -type f -print0 | xargs -0 du -h | sort -rh | head -n 10
du: 无法访问"/proc/4157/task/4157/fdinfo/6": 没有那个文件或目录
102M /usr/lib/locale/locale-archive
78M /usr/bin/dockerd-ce
66M /usr/bin/docker
64M /var/lib/rpm/Packages
52M /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
43M /usr/bin/containerd
30M /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29M /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28M /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
27M /opt/microsoft/powershell/6-preview/System.Management.Automation.dll
------- [ linux 的 find 命令 3,返回的结果] -------
find / -type f -ls | sort -k 7 -r -n | head -10 | column -t | awk '{print $7,$11}'
find: ‘/proc/4267/task/4267/fdinfo/6 ’: 没有那个文件或目录
find: ‘/proc/4267/fdinfo/5 ’: 没有那个文件或目录
140737486266368 /proc/kcore
106075056 /usr/lib/locale/locale-archive
81655064 /usr/bin/dockerd-ce
68559960 /usr/bin/docker
66072576 /var/lib/rpm/Packages
53641389 /boot/initramfs-0-rescue-314df5eb857b4ced8b7d82f9365999e7.img
44345152 /usr/bin/containerd
31059968 /var/cache/yum/x86_64/7/base/gen/primary_db.sqlite
29782016 /var/cache/yum/x86_64/7/epel/gen/primary_db.sqlite
28327936 /opt/microsoft/powershell/6.0.5/System.Management.Automation.dll
------- [我的疑问] -------
问 1:linux 上所有都是文件么?
是的话,find,du 为什么会报那些错?谁来答答?
问 2:/proc/kcore 是文件么?
测试代码:
root@centos76 ~]#ls -l
-r--------. 1 root root 140737486266368 3 月 20 10:57 /proc/kcore
问:find 不加 [-print0 ] 参数后,能算 [最大 10 个文件] 么?
答:不行。
欢迎帮忙测试,下面的命令:
find / -type f | xargs -0 du -h | sort -rh | head -n 10
或
find / -type f | xargs du -h | sort -rh | head -n 10
问:加上 [-print0 ] 参数后,返回消失了,这是 find 的 bug 么?
测试代码:
[root@centos76 ~]# find /proc -name 'kc*' -type f
/proc/kcore
/proc/kcore[root@centos76 ~]# find /proc -name 'kc*' -type f -print0
返回空,即无返回
问: [ find / -type f -exec du -sh {}] 也有丢文件的 bug,对么?
答:
应该是 du 的问题。
测试代码:
find /proc -name 'kc*' -type f
/proc/kcore
find /proc -name 'kc*' -type f -exec du -sh {} +
0 /proc/kcore
------- [结论] -------
我认为:
[ linux 的 powershell 命令 1,返回的结果]
[ linux 的 find 命令 3,返回的结果]
靠谱点。
虽然 [/proc/kcore ] 返回的结果我并不需要。
当然,我也认为,没占磁盘,du 不应该返回。
powershell 那两个返回都是可以的,find 的返回就不乐观了。