如何修复以下行:
for line in $(cat /root/files_to_search); do find /opt/ -iname $line -exec rm {} >> files_founded.txt ; done
问题是for
和-exec
的命令以分号结尾,for
命令有此语句
for i in something; do command ; done (do terminate with ;)
带有find
的和-exec
声明
find /path/ -name somestring -exec command \; (-exec also finish with ;)
答案 0 :(得分:2)
您甚至不需要使用-exec echo {}
,因为这是find
中的默认操作。您可以使用此for循环:
while IFS= read -r line; do
find /opt/ -iname "$line"
done < /root/files_to_search >> files_founded.txt
您无需使用for line in $(cat ...)
,因为您可以使用< file
来读取输入
See BASH FAQ on reading a file line by line
如果您必须在-exec
中使用find
,请使用:
while IFS= read -r line; do
find /opt/ -iname "$line" -exec rm {} \;
done < /root/files_to_search >> files_founded.txt