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

请教一个问题,chmod 命令怎么样排除指定的目录

  •  
  •   Tink ·
    PRO
    ·
    goxofy · Mar 14, 2014 · 4089 views
    This topic created in 4467 days ago, the information mentioned may be changed or developed.
    现在有一个特殊需求,需要定期对一个大目录下的所有文件和文件夹赋予777权限,但是需要排除其中的两个目录,这两个目录以及目录下的文件的权限不能有任何变化

    求指点。
    8 replies    1970-01-01 08:00:00 +08:00
    nicai000
        1
    nicai000  
       Mar 14, 2014
    配合find
    Tink
        2
    Tink  
    OP
    PRO
       Mar 14, 2014
    @nicai000 额,find应该只能指定哪些目录被执行吧?也能排除么

    我最后用脚本弄了,虽然有点麻烦

    do
    if [ $file != "1" ]&&[ $file != "2" ]; then
    chmod -R 777 $file
    fi
    done
    nicai000
        3
    nicai000  
       Mar 14, 2014
    像这样?

    find ~/ ! -name foo ! -name bar -exec chmod -R 777 {} \;
    Tink
        4
    Tink  
    OP
    PRO
       Mar 14, 2014
    @nicai000 好顶赞!
    nicai000
        5
    nicai000  
       Mar 14, 2014
    find好像是不是很对, 那么这样? (我都没试过哈)

    ls -1|grep -v foo|grep -v bar|xargs chmod -R 777
    sandtears
        6
    sandtears  
       Mar 14, 2014
    其实有个蠢办法,先移出去然后777然后移回来。。。
    zent00
        7
    zent00  
       Mar 14, 2014
    chmod -R 777 !(1|2)
    webjin
        8
    webjin  
       Mar 20, 2014 via Android
    @zent00 正则???
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2850 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 04:25 · PVG 12:25 · LAX 21:25 · JFK 00:25
    ♥ Do have faith in what you're doing.