您现在的位置是:网站首页> 编程资料编程资料
bash批量修改文件名称的方法小结(增加,去除,修改后缀)_linux shell_
2023-05-26
3653人已围观
简介 bash批量修改文件名称的方法小结(增加,去除,修改后缀)_linux shell_
一、加后缀
1.问题:同以目录下有海量以日期命名的文件,其中有的有后缀,有的以点结尾,如20020101.,20020102.,……,20020101.td,20020102.td……
要求: 把所有以点结尾的加上后缀.ts
我的方法:
复制代码 代码如下:
#!/bin/bash
for files in `ls *.`
do
mv $files `echo "$filests" `
done
2. 同上
mv $files ${files}ts
3. 同上
mv $files `$files.ts|sed 's/\.//' `
4. file =>file.txt
mv $files $files.txt
5. *.04 => *04.txt
mv $files $(echo ${files}.txt|sed 's/\.//1')
或
mv $files `echo ${files}.txt|sed 's/\.//1' `
二、改后缀(.old => .new)
复制代码 代码如下:
1. rename
rename .old .new *
2.
mv $files ${file%.old}.new
3.
mv $files `echo $files|tr .old .new`
4.
mv $files `echo $files|sed 's/\.old/\.new/' `
三、去后缀 (*.dat => *)
复制代码 代码如下:
1. mv $files `echo $files |sed 's/\.dat//' `
2. mv $files `echo $files|tr .dat (4空格)`
四、改前缀 (re* => un*)
复制代码 代码如下:
1. mv $files un${$files#re}
2. mv $files `echo $files | tr re un`
您可能感兴趣的文章:
相关内容
- linux shell自定义函数(定义、返回值、变量作用域)介绍_linux shell_
- shell查找符号链接及其指向目标的方法介绍_linux shell_
- shell自定义函数及参数调用解析_linux shell_
- linux和windows下的自动ftp脚本(shell bat)_linux shell_
- sed或awk处理文件最后一行的实现方法_linux shell_
- awk区间取值的例子_linux shell_
- Linux 脚本编写基础知识_linux shell_
- 浅析linux下如何用脚本自动发送文本mail邮件_linux shell_
- linux脚本实现自动发送和收取邮件的设置方法_linux shell_
- linux shell脚本基础知识学习_linux shell_
