Tar .sh 文件中的搜索结果

Tar search results in .sh file

我必须 tar 一个没有路径的文件列表,这是通过 sh 查找的结果(供 crontab 使用)。

在 ubuntu 的 shell 中,每个命令都可以正常工作,但在 .sh 中则不行。

我试过:


#!/bin/sh
tar -zcvf  /destination/one-$(date +"%Y%m%d").tgz < find /myfolder/ -iname 'one*' -printf '%f\n'

还有


#!/bin/sh
find /myfolder/ -iname 'one*' -print0 | tar -czvf /destination/one-$(date +"%Y%m%d").tar.gz --null -T - 

但都失败了。有人可以帮忙吗?备选方案 ?

其他场景信息:

我认为您希望在 stdin 上将文件名传递给 tar :

find . -name \*.png -print0 | tar -cv --null -T- -f tarball.tar

以我为例:

find /myfolder/ -iname "one*" -print0 | tar -czv --null -T- -f /destination/one-$(date +"%Y%m%d").tar.gz