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

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

  •  1
     
  •   station · May 19, 2016 · 6077 views
    This topic created in 3842 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
    ToughGuy
    May 19, 2016
    1
    先执行这个:
    shopt -s extglob

    然后再试

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