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

Passing command as input to diff command in bash

我正在尝试比较服务器的文件系统状态,并将基准(初始状态)存储在一个 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'