【发布时间】:2019-05-21 01:50:58
【问题描述】:
我在变量中排序有问题。
我使用 Bash 和 NSH 控制台。
我加载到操作系统中可变的最大文件夹:
vdirList=$(nexec -e "find /etc -type d -size +1k -print0 | xargs -0 du -h --max-depth 3 --time --time-style +'%F %T %z' 2>/dev/null| sort -h -k1 2>/dev/null| tail -7 | sed -n '$ ! p' | uniq -c | tac | sed 's/^/BAORES: /'")
vdirList+="\n"
vdirList+=$(nexec -e "find /usr -type d -size +1k -print0 | xargs -0 du -h --max-depth 3 --time --time-style +'%F %T %z' 2>/dev/null| sort -h -k1 2>/dev/null| tail -7 | sed -n '$ ! p' | uniq -c | tac | sed 's/^/BAORES: /'")
vdirList+="\n"
这是输出:
BAORES: 3 22M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted
BAORES: 2 22M 2017-05-05 14:53:20 +0300 /etc/selinux
BAORES: 1 13M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted/modules
BAORES: 2 1.9G 2018-12-20 05:49:04 +0200 /usr/lib
BAORES: 3 1.3G 2018-12-20 05:48:55 +0200 /usr/lib/x86_64-linux-gnu
BAORES: 1 445M 2018-12-20 05:49:04 +0200 /usr/lib/i386-linux-gnu
我想按 3 列对这些文件进行排序,我使用以下命令:
dirList=$(nexec -e "echo \"$vdirList\" | sort -hrk3 | head -n 10")
但我的输出是:
BAORES: 3 22M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted
BAORES: 3 1.3G 2018-12-20 05:48:55 +0200 /usr/lib/x86_64-linux-gnu
BAORES: 2 22M 2017-05-05 14:53:20 +0300 /etc/selinux
BAORES: 1 445M 2018-12-20 05:49:04 +0200 /usr/lib/i386-linux-gnu
BAORES: 1 13M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted/modules
BAORES: 2 1.9G 2018-12-20 05:49:04 +0200 /usr/lib
有人可以帮忙吗?谢谢。
【问题讨论】: