
我正在尝试通过 netcat 发送大量 json 文件,但似乎无法正确使用 find -exec 组合。我在包含 json 文件的目录中,并尝试了以下操作:
find -iname "*.json" -type f -exec netcat 127.0.0.1 6002 < {} \;
返回-bash: {}: No such file or directory
find -iname "*.json" -type f -exec cat {} | netcat 127.0.0.1 6002 \;
返回find: missing argument to '-exec'
答案1
我在以下人员的帮助下找到了答案https://unix.stackexchange.com/a/389706/254118:
find -iname "*.json" -type f -exec sh -c 'cat $1 | netcat 127.0.0.1 6002' sh {} ';'