目录
1 文件操作
1.1 查找文件并执行
find . -name 文件名 -exec cp {} 目的路径 \;
1.2 查找文件并重命名
find . -type f -name "old*" -exec bash -c 'mv "$1" "${1/old/new}"' _ {} \; #查找以old开头的文件,修改为new开头
1.3 查找文件并替换内容
find . -type f -exec sed -i 's/old_content/new_content/g' {} +
1.4 hexdump mtd的内容
"%08_ax "表示16进制打印地址,8位补齐
16/1 "%02x " 表示每行打印16个字节,每个字节为2位补齐
hexdump -e '"%08_ax " 16/1 "%02x ""\n"' /dev/mtd4
2 字符串操作
2.1 字符串包含/替换
2.1.1 字符串替换
- 替换第1个
str='string_full_full'
substr="${str/full/sub}"
echo $substr #输出为string_sub_full
- 替换所有
str='string_full_full'
substr="${str//full/sub}"
echo $substr #输出为string_sub_sub
- 删除字符串中所有数字
str='str123'
echo ${str//[0-9]/}
2.1.2 字符串包含
str='string_full'
[ "${str/full/}" = "$str" ] || echo "I'm full string" #包含
[ "${str/sub/}" = "$str" ] && echo "I'm not sub string" #不包含
3 数值运算
$(awk "BEGIN { printf \"%.0f\", $txRate / 1000 }") #除以1000,小数点后面不留位数