小编Bla*_*ker的帖子

'ls' 在使用 find 命令时由信号 13 终止

所以我试图运行一个脚本,该脚本搜索 df -h 的内容以查找超过阈值的目录,并且基本上在该目录上运行 find 命令以获取前十个最大的文件,然后停止运行 find。但是,当它按预期给出前十个文件时,它会多次吐出:

find: ‘ls’ terminated by signal 13
Run Code Online (Sandbox Code Playgroud)

我的问题很简单,我该如何阻止这些?我想我明白这些是由于我的 find 命令和 head -n 10 命令同时运行,因为 head 在 find 之后通过管道传输,但如果有人能详细说明,那就太好了。我的目标是将此提交给工作中的权力(沃尔玛),以便在我们的测试服务器上开始运行。

另请注意,find 命令中的大小仅为 5M,因为我的测试服务器上没有 10 个在该目录中那么大的文件。

这是脚本:

#!/bin/bash

#defines what exceeds threshold

threshold="90%|91%|92%|93%|94%|95%|96%|97%|98%|99%|100%|6%"

#puts the output of df -h  into output_df

df -h > output_df

cat output_df | awk -v VAR=$threshold '{if($5~VAR)print $6}' > exceeds_thresh

LINES=()
while IFS= read -r exceeds_thresh
do
find $exceeds_thresh -xdev -size +5M -exec ls -lah {} \; | head -n 10
done …
Run Code Online (Sandbox Code Playgroud)

linux bash shell server-administration

6
推荐指数
2
解决办法
5605
查看次数

标签 统计

bash ×1

linux ×1

server-administration ×1

shell ×1