Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
station
V2EX  ›  Linux

rm 命令如何保留某个或多个文件?

  •  1
     
  •   station · May 19, 2016 · 5689 views
    This topic created in 3675 days ago, the information mentioned may be changed or developed.
    网上盛传 rm -rf !(文件名)这种参数,但我这里总提醒我 -bash: !: event not found
    12 replies    2016-05-19 16:46:12 +08:00
    ToughGuy
        1
    ToughGuy  
       May 19, 2016
    先执行这个:
    shopt -s extglob

    然后再试

    rm -rf !(文件名)
    clino
        2
    clino  
       May 19, 2016
    你可以用 find .|grep xxx|xargs rm -rfv
    这样在 grep 这里可以用正则表达式之类的过滤
    station
        3
    station  
    OP
       May 19, 2016
    @ToughGuy 谢谢,搜索了原来是 extglob 模式没开
    station
        4
    station  
    OP
       May 19, 2016
    @clino 没试,还是感谢你
    ffffwh
        5
    ffffwh  
       May 19, 2016 via Android
    rm 一时爽
    station
        6
    station  
    OP
       May 19, 2016
    @ffffwh 此话怎讲
    ffffwh
        7
    ffffwh  
       May 19, 2016 via Android
    @station
    就是说容易误删文件
    gqkkk
        8
    gqkkk  
       May 19, 2016
    find 条件|xargs rm
    qwerasdf
        9
    qwerasdf  
       May 19, 2016
    删除 the/dir 目录下的多个指定文件
    rm `ls -a the/dir grep | xxx`
    xiaoz
        10
    xiaoz  
       May 19, 2016 via iPhone
    cxbig
        11
    cxbig  
       May 19, 2016
    建议用 find 出来结果再用 rm ,容易把握。
    reticentfat
        12
    reticentfat  
       May 19, 2016
    rm -f `ls *.*|egrep -v "(a.bbb|*.ccc)"`
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3891 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 05:04 · PVG 13:04 · LAX 22:04 · JFK 01:04
    ♥ Do have faith in what you're doing.