hackpro
V2EX  ›  问与答

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

  •  
  •   hackpro · Nov 21, 2017 · 1545 views
    This topic created in 3144 days ago, the information mentioned may be changed or developed.

    举个例子

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

    产生了 hello

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

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

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

    5 replies    2017-11-21 13:27:40 +08:00
    geelaw
        1
    geelaw  
       Nov 21, 2017 via iPhone
    看 file mode
    acgnsstech
        2
    acgnsstech  
       Nov 21, 2017
    rm -rf /
    knightdf
        3
    knightdf  
       Nov 21, 2017
    `find /path/to -type f -executable -exec rm {} \;`
    bigeast
        4
    bigeast  
       Nov 21, 2017
    rm $(find * -type f -perm +111)

    +111 代表文件是可执行的。新版的 find 可能是 /111,而且有一个 -executable 参数,你去 man 一下看看
    oxoxoxox
        5
    oxoxoxox  
       Nov 21, 2017 via iPad
    man find 看里面的-perm 说明
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   978 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 22:26 · PVG 06:26 · LAX 15:26 · JFK 18:26
    ♥ Do have faith in what you're doing.