nonozone
V2EX  ›  问与答

请教个linux文件批量处理的问题,救急。

  •  
  •   nonozone · Jan 26, 2013 · 3901 views
    This topic created in 5041 days ago, the information mentioned may be changed or developed.
    我现在有一堆网站要修改配置文件,紧紧是修改里面配置文件的数据库密码
    比如
    aaa.com/html/config.php
    bbb.com/html/config.php
    ...


    zzz.com/html/config.php

    所有都是修改config.php这个文件里吧里面数据库密码的字符串从“xxxxxxx”换成“yyyyy”。

    有没有办法?

    顺便请教个mysql的问题,同样也需要需改这一批网站的用户密码,我知道怎么修改单个网站的用户密码,但是在phpmyadmin如何把这些网站的用户密码都改过来?请教这个mysql命令啊...
    14 replies  •  1970-01-01 08:00:00 +08:00
    momou
    momou
    Jan 26, 2013
    1
    第一个问题
    sublime text 2-->find-->find in files 查找替换
    nonozone
    nonozone
    OP
    Jan 26, 2013
    2
    @momou 如果是vim呢,在服务器上呢...
    momou
    momou
    Jan 26, 2013
    3
    不会vim,grep能满足你的要求,具体谷歌吧。。。
    laoyang945
    laoyang945
    Jan 26, 2013
    4
    vim里面用args载入文件列表,用argdo执行批量操作,细节请google
    Kymair
    Kymair
    Jan 26, 2013
    5
    find /srv/htdocs -name "config.php" -exec sed -i 's/xxxxxx/yyyyy/g' {} \;
    swulling
    swulling
    Jan 26, 2013
    6
    ls各种不靠谱啊

    在最上层目录用

    find . -type f -name "config.php" | xargs -i sed -i 's/xxxxxx/yyyyyyy/g' {}
    nonozone
    nonozone
    OP
    Jan 26, 2013
    7
    请教个楼上两位,最后面的那个 {} 代表的啥意思?

    还有数据库不能替换mysql里所有数据库么?
    nonozone
    nonozone
    OP
    Jan 26, 2013
    9
    @swulling 这个好像是修改数据库密码的。

    现在我已经知道单个数据库里如何替换字段,就是不知道有没有方法把所有的数据库都走一次这个命令。mysql有没有类似用 * 匹配所有数据库的功能?
    swulling
    swulling
    Jan 26, 2013
    10
    @nonozone 我看错题目了。。你可以用shell组合一下mysql命令
    Kymair
    Kymair
    Jan 27, 2013
    11
    @swulling 麻烦问一下我提供的command里面哪里写错了吗?
    swulling
    swulling
    Jan 27, 2013
    12
    @Kymair 没错啊,只不过我回复的时候你的回复还没刷出来,只差几s
    BOYPT
    BOYPT
    Jan 28, 2013
    13
    ...你们用户网站密码的位置还不一样啊,居然用的上匹配……
    nonozone
    nonozone
    OP
    Jan 29, 2013
    14
    @BOYPT 一样啊,但是域名目录不同啊。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1973 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 02:17 · PVG 10:17 · LAX 18:17 · JFK 21:17
    ♥ Do have faith in what you're doing.