shell实用技巧 shell脚本将所有文件夹以文件中特定字符串重命名#!/bin/bash # 目标目录 target_dir$1 # 遍历目标目录下的所有文件夹 for dir in $target_dir/*; do if [ -d $dir ]; then echo $dir extracted_lines$(grep transId $dir/pos.json -rw | awk -F \ {print $4}) echo $extracted_lines mv $dir $target_dir/$extracted_lines # echo $target_dir/$extracted_lines fi done在/proc/filesystems文件中检查所有是否有 以一个或多个空格vfat结尾的行#!/bin/bash if ! grep -E -qs [[:space:]]vfat\$ /proc/filesystems; then echo not found else echo found fi-E 扩展正则表达式-qs 判断是否存在-q选项用于if逻辑判断安静模式不打印任何标准输出如果有匹配的内容则立即返回状态值-s选项会在发现不存在或者不能读取的文件时隐藏报错信息