gpt4 book ai didi

linux - 将命令作为输入传递给 bash 中的 diff 命令

转载 作者:太空宇宙 更新时间:2023-11-04 10:35:38 24 4
gpt4 key购买 nike

我正在尝试比较服务器的文件系统状态,并将基准(初始状态)存储在一个 initialSnapshot.log 文件中。现在我正在尝试将它与运行时数据进行比较,因此我可以回显文件统计信息中的任何更改。

#Capture the filesystem stats at the start and store them in initialSnapShot.log file.

find storage1 -type f -ls > initialSnapShot.log

#While loop to keep continues check on stats.

while true
do
#Below command does not work
diff --suppress-common-lines -y `find storage1 -type f -ls` initialSnapShot.log


done

然而,它并没有按计划工作

diff: invalid option -- -
diff: Try `diff --help' for more information.

请建议任何更好的设计方法?我应该将 find 的输出存储在第二个文件中吗(看起来很脏)?

编辑:

find storage1 -type f -ls
3366871 439652 -rw-rw-r-- 1 randomUser random 449314816 Jun 8 07:47 storage1/bla1
3366884 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:29 storage1/blass
4639952 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:44 storage1/blass222122
4639950 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:33 storage1/blass2221
4639951 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:33 storage1/blass22212
4639953 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:45 storage1/blass2221221
4639954 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:47 storage1/blass22212211
4639955 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:47 storage1/blass2221221121

最佳答案

你在使用 bash 吗?如果是这样,请尝试使用 bash 进程替换:

diff --suppress-common-lines -y <(find storage1 -type f -ls) initialSnapShot.log

或者,如果您不使用 bash,请尝试明确指定它

bash -c 'diff --suppress-common-lines -y <(find storage1 -type f -ls) initialSnapShot.log'

关于linux - 将命令作为输入传递给 bash 中的 diff 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37721547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com