douqiu0796 2015-07-23 20:38
浏览 323
已采纳

在bash中包含和排除globbing模式

I am trying to use the PHPCompatibility standard for PHP CodeSniffer to test a specific set of files.

I'm currently using find to do this.

find ./path1 ./path2 ./path3 ./path4                                                \
    -type f                                                                         \
    -name '*.php'                                                                   \
    -not -path './path4/dontwantthis/*'                                             \
    -exec ./vendor/bin/phpcs                                                        \
    --standard=PHPCompatibility --runtime-set testVersion 5.6 {}                    \;

However, this is really slow and inefficient because the startup for the script runs for every single file.

The phpcs script takes in a path like ./vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 5.6 <path-of-your-php-files> and I'd like to find a way to replicate the find stuff with a globbing pattern in place of the <path-of-your-php-files>

One of the major problems I was having was including ./path4/*.php while also excluding ./path4/dontwantthis/*

  • 写回答

1条回答 默认 最新

  • duanbangzhou7809 2015-07-23 21:04
    关注

    End your -exec option with + instead of \;. That tells find to run the command once with all the filenames, rather than separately for each filename.

    find ./path1 ./path2 ./path3 ./path4                                                \
        -type f                                                                         \
        -name '*.php'                                                                   \
        -not -path './path4/dontwantthis/*'                                             \
        -exec ./vendor/bin/phpcs                                                        \
        --standard=PHPCompatibility --runtime-set testVersion 5.6 {} +
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀