How to use pipe within -exec in find

前端 未结 2 1055
感情败类
感情败类 2020-12-09 08:29

Is there any way to use pipe within an -exec in find? I don\'t want grep to go through whole file, but only through first line of each file.

find /path/to/di         


        
2条回答
  •  天命终不由人
    2020-12-09 09:12

    This does not directly answer your question, but if you want to do some complex operations you might be better off scripting:

    for file in $(find /path/to/dir -type f); do echo ${file}; cat $file | head -1 | grep yourstring; done

提交回复
热议问题