1.文件重命名
语法:mv source_file target_file
场景模拟:把文件夹BeiJing修改成HangZhou
#!/bin/bash
mv "/cygdrive/C/folder/BeiJing" "/cygdrive/C/folder/HangZhou"
2.替换字符
全文匹配对应的字符进行替换
场景模拟:把readme.txt文件中,所有“name=”替换成“name=Jaychou”
#!/bin/bash
file_path=/cygdrive/c/folder/readme.txt
sed -i "s/name=/name=Jaychou/g" $file_path
- s选项:用一个字符串替换另外一个字符串
-
g选项:在行内进行全局替换
全文匹配到对应字符,整行替换
#!/bin/bash
file_path=/cygdrive/c/folder/readme.txt
sed -i "/name=/c\name=Jaychou" $file_path