I would like to do something like:
find . -type f -exec test $(file --brief --mime-type '{}' ) == 'text/html' \; -print
but I can’t figure out the correct way to quote or escape the args to test, especially the ‘$(‘ … ‘)’ .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot simply escape the arguments for passing them to
find.Any shell expansion will happen before
findis run.findwill not pass its arguments through a shell, so even if you escape the shell expansion, everything will simply be treated as literal arguments to thetestcommand, not expanded by the shell as you are expecting.The best way to achieve what you want would be to write a short shell script, which takes the filename as an argument, and use
-execon that:with
is_html.sh:If you really want it all on one line, without using a separate script, you can invoke
shdirectly fromfind: