1. 首先用find命令找到满足条件的文件,把结果重定向到文件old(find寻找的对象里面包含正则匹配符号时记得外面要用单引号,否则会报错)
[/var] # find / -type f -name '*.LOG' > old 2> /dev/null
/root/download/readline-6.0/config.LOG
/root/download/rlwrap-0.30/config.LOG
/root/.local/share/gvfs-metadata/computer:-ce73b7ac.LOG
/root/.local/share/gvfs-metadata/trash:-2b5aca0c.LOG
/root/.local/share/gvfs-metadata/home-767242eb.LOG
/root/.local/share/gvfs-metadata/root-acf8eecb.LOG
/root/shell/apache.LOG
/root/.imsettings.LOG
2.变量循环读取文件old,使用替换方法,生成mv命令到新文件mv,先不执行生成的mv命令(注意命令中do和done后面没有分号)。
[/var] # for i in `cat old`;do echo mv $i ${i/.LOG/.log}; done > mv 2> /dev/null
3.检查文件mv内容是否正确,确认后直接执行这个文件中的命令即可
[/var] # more mv
mv /root/download/readline-6.0/config.LOG /root/download/readline-6.0/config.log
mv /root/download/rlwrap-0.30/config.LOG /root/download/rlwrap-0.30/config.log
mv /root/.local/share/gvfs-metadata/computer:-ce73b7ac.LOG /root/.local/share/gvfs-metadata/computer:-ce73b7ac.log
mv /root/.local/share/gvfs-metadata/trash:-2b5aca0c.LOG /root/.local/share/gvfs-metadata/trash:-2b5aca0c.log
mv /root/.local/share/gvfs-metadata/home-767242eb.LOG /root/.local/share/gvfs-metadata/home-767242eb.log
mv /root/.local/share/gvfs-metadata/root-acf8eecb.LOG /root/.local/share/gvfs-metadata/root-acf8eecb.log
mv /root/shell/apache.LOG /root/shell/apache.log
mv /root/.imsettings.LOG /root/.imsettings.log
4.如果在第二步中不想保存mv语句,直接执行mv命令,那就换如下命令
[/var] # for i in `cat old`;do mv $i ${i/.LOG/.log}; done 2> /dev/null bash -x
--转自