初学linux,总结了三种批量更改文件名的方法,应该是运维面试大几率会考到的内容linux
借鉴了网上看来的思路面试
要求 将文件名中的test字符替换为truebash
1、rename运维
rename命令做为最专业的工具在重命名方面当仁不让,方法十分简单
ide
rename true test *.txt工具
2、awk拼接it
利用awk的拼接
for循环
ls *|awk -F 'test' '{print $1"true"$2}'class
以须要替换的单词做为分隔符,分开原文件名,中间插入须要更改的文件名
test
3、for循环
#!/bin/bash
for file in ` ls *.txt `
do
mv "$file" ` echo $file|sed 's#test#true#g' `
done
须要写成脚本,for命令遍历文件,挨个mv更改文件名