在我的 Linux 计算机中,我有/dev/mapper/
许多文件名为file1
、、....。file2
file3
现在我将从文件中了解密码的使用频率。
我试过这个
for i in /dev/mapper/file* ; do cryptsetup status $i | grep cipher ; done | sort
并成为这个输出
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-cbc-essiv:sha256
cipher: aes-xts-plain64
cipher: aes-xts-plain64
cipher: aes-xts-plain64
cipher: serpent-xts-plain64
cipher: serpent-xts-plain64
但我正在寻找这样的输出:
13x cipher: aes-cbc-essiv:sha256
3x cipher: aes-xts-plain64
2x cipher: serpent-xts-plain64
另外还有如下输出:
file1 use cipher aes-xts-plain64
file2 use cipher serpent-xts-plain64
....
file13 use cipher aes-xts-plain64
在
bash
:我没有使用,
cryptsetup
因此我将创建以下文件来模拟输出cryptsetup
:为了模拟跑步,
cryptsetup status $i
我将运行cat $i
,例如:由于我不熟悉
cryptsetup
输出,我将find
打印文件名然后调用cat
:我现在可以将其输入到
awk
来累加计数,将file use cipher
行打印到cipher_list.txt
,最后将总计数打印到cipher_counts.txt
:结果:
从这里开始,OP 可以运行文件
sort
并column
根据需要进行格式化。我们可以在代码中推动排序和最终打印格式,但此时awk
我想让代码保持(相对)简单。awk
例如,
cipher_list.txt
按文件名排序(假设每个文件只有一行/一个密码)并以至少 1 个空格隔开列:至于 OP 的实际环境,我假设 OP 做出以下更改就足够了: