hackpro
V2EX  ›  问与答

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

  •  
  •   hackpro · Nov 21, 2017 · 1722 views
    This topic created in 3300 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
    geelaw
    Nov 21, 2017 via iPhone
    1
    看 file mode
    acgnsstech
    acgnsstech
    Nov 21, 2017
    2
    rm -rf /
    knightdf
    knightdf
    Nov 21, 2017
    3
    `find /path/to -type f -executable -exec rm {} \;`
    bigeast
    bigeast
    Nov 21, 2017
    4
    rm $(find * -type f -perm +111)

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