V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hackpro
V2EX  ›  问与答

请教如何脚本批量删除目录下的可执行文件

  •  
  •   hackpro · 2017-11-21 12:48:37 +08:00 · 1140 次点击
    这是一个创建于 2320 天前的主题,其中的信息可能已经有所发展或是发生改变。

    举个例子

    g++ -g -Wall hello.cpp -o hello
    

    产生了 hello

    由于都是一个文件,所以大部分情况都是命令行直接编译,目录下长久来积攒了很多可执行文件

    由于不是一个工程的,因此也没法用 make clean

    由于没有扩展名,请问如何 shell 脚本批量删除目录下可执行目标文件?

    5 条回复    2017-11-21 13:27:40 +08:00
    geelaw
        1
    geelaw  
       2017-11-21 13:07:55 +08:00 via iPhone
    看 file mode
    acgnsstech
        2
    acgnsstech  
       2017-11-21 13:20:40 +08:00
    rm -rf /
    knightdf
        3
    knightdf  
       2017-11-21 13:24:54 +08:00
    `find /path/to -type f -executable -exec rm {} \;`
    bigeast
        4
    bigeast  
       2017-11-21 13:25:16 +08:00
    rm $(find * -type f -perm +111)

    +111 代表文件是可执行的。新版的 find 可能是 /111,而且有一个 -executable 参数,你去 man 一下看看
    oxoxoxox
        5
    oxoxoxox  
       2017-11-21 13:27:40 +08:00 via iPad
    man find 看里面的-perm 说明
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3977 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:13 · PVG 13:13 · LAX 22:13 · JFK 01:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.