代码之家  ›  专栏  ›  技术社区  ›  Steven D. Majewski

bash:find命令中的复杂测试

  •  1
  • Steven D. Majewski  · 技术社区  · 16 年前

    我想做如下的事情:

    find . -type f -exec test $(file --brief --mime-type '{}' ) == 'text/html' \; -print 
    

    但我无法找到正确的引用或转义参数进行测试的方法,尤其是“$(”..')”.

    3 回复  |  直到 16 年前
        1
  •  9
  •   Brian Campbell Dennis Williamson    16 年前

    find

    test

    -exec

    find . -type f -exec is_html.sh {} \; -print
    

    is_html.sh

    #!/bin/sh
    
    test $(file --brief --mime-type "$1") == 'text/html'
    

    sh

    find . -type f -exec sh -c 'test $(file --brief --mime-type "$0") == "text/html"' {} \; -print
    
        2
  •  1
  •   msw    16 年前

    $ find . -type f -print0 | xargs -0 file --mime-type | ↷
       grep ':[^:]*text/html$'| sed 's,:[^:]*text/html,,'
    
        3
  •  0
  •   user268396    16 年前

    find * -maxdepth 0 -exec file "{}" \;
    
    推荐文章