substitute Chapter to Ch and chapter to ch in springboot idea project

1 relative skills

1.1 linux批量替换目录下所有文件中的某字符串

  1. method1: 比如,要将目录/modules下面所有文件中的zhangsan都修改成lisi,这样做:
    sed -i "s/zhangsan/lisi/g" `grep zhangsan -rl /modules`

解释一下:
-i 表示inplace edit,就地修改文件
-r 表示搜索子目录
-l 表示仅输出匹配的文件名,不输出匹配到的那一行的具体内容

  1. method2: linux shell 字符串中指定字符替换
    echo ${"abc1234bb1234"/23/bb} //abc1bb42341 替换一次
    echo ${string//23/bb} //abc1bb4bb41 双斜杠替换所有匹配
    echo ${string/#abc/bb} //bb12342341 #以什么开头来匹配,根php中的^有点像
    echo ${string/%41/bb} //abc123423bb %以什么结尾来匹配,根php中的$有点像

1.2 批量更改目录下所有文件名(如修改后缀名)

  1. method1: 命令格式: rename 's/.csv/.txt/' *
    我想把当前目录下所有的txt文件都修改为后缀为csv,如果一个一个的修改,很耗费时间,效率低,只要执行这个命令,一下就搞定。

  2. method2: for i in 3_*; do mv $i $i".txt"; done
    利用for循环,遍历所有有特定特征的文件,然后给其重命名。

2 steps

2.1 substitute folder names: chapter to ch

  1. target folders:
    /d/develop/ideaws/parentProject/chapter*
    find /d/develop/ideaws/parentProject/ -name *chapter*
    (actually, folders whose name contains chapter only exists in /d/develop/ideaws/parentProject/chapter*, so we don't need to handle find /d/develop/ideaws/parentProject/ -name *chapter* )

  2. monitor the effect in advance
    for i in /d/develop/ideaws/parentProject/*; do echo ${i/chapter/ch}; done

  3. substitute
    for i in /d/develop/ideaws/parentProject/*; do mv $i ${i/chapter/ch}; done

  4. verfiy the result
    ll /d/develop/ideaws/parentProject/

2.2 substitute folder names: Chapter to Ch

  1. target folders:
    find /d/develop/ideaws/parentProject/ -name *Chapter*
  2. monitor the effect in advance
    for i in `find /d/develop/ideaws/parentProject/ -name *Chapter*`; do echo ${i/Chapter/Ch}; done
  3. substitute
    for i in `find /d/develop/ideaws/parentProject/ -name *Chapter*`; do mv $i ${i/Chapter/Ch}; done
  4. verfiy the result
    find /d/develop/ideaws/parentProject/ -name *Chapter*
    find /d/develop/ideaws/parentProject/ -name *Ch*

2.3 substitute file names: Chapter to Ch

  1. target files:
    grep Chapter -rl /d/develop/ideaws/parentProject/

  2. substitute
    sed -i "s/Chapter/Ch/g" `grep Chapter -rl /d/develop/ideaws/parentProject/`

  3. verfiy the result
    grep Chapter -rl /d/develop/ideaws/parentProject/

2.4 substitute file names: chapter to ch

  1. target files:
    grep chapter -rl /d/develop/ideaws/parentProject/

  2. substitute
    sed -i "s/chapter/ch/g" `grep chapter -rl /d/develop/ideaws/parentProject/`

  3. verfiy the result
    grep chapter -rl /d/develop/ideaws/parentProject/

2.5 this 3 git metadata files shoule not be substituted

/d/develop/ideaws/parentProject/.git/index
/d/develop/ideaws/parentProject/.git/logs/HEAD
/d/develop/ideaws/parentProject/.git/logs/refs/heads/main

  1. method1: use old git files to replace the new files which are substituted.
    cp /d/develop/ideaws/parentProject/.git/index /d/develop/ideaws/parentProject/.git/
    cp /d/develop/ideaws/parentProject/.git/logs/HEAD /d/develop/ideaws/parentProject/.git/logs/HEAD
    cp /d/develop/ideaws/parentProject/.git/logs/refs/heads/main /d/develop/ideaws/parentProject/.git/logs/refs/heads/main

  2. method2:
    firstly move the .git/ folder to other path. after all steps complete, move back the .git/

2.6 open idea to check whether there are other problems

2.7 if there is no problem, submit the code with 'git commit'

posted @ 2021-08-26 12:38  mediocrep  阅读(44)  评论(0编辑  收藏  举报
既然选择了远方,便只顾风雨兼程!