linux 中 批量删除文件后缀

 

001、rename

[root@PC1 test]# ls
1.csv  2.csv  3.csv  a.txt  b.txt  c.txt
[root@PC1 test]# rename ".txt" "" *.txt      ## 删除.txt后缀
[root@PC1 test]# ls
1.csv  2.csv  3.csv  a  b  c
[root@PC1 test]# rename ".csv" "" *.csv      ## 删除.csv后缀
[root@PC1 test]# ls
1  2  3  a  b  c

 

002、

[root@PC1 test]# ls
1.csv  2.csv  3.csv  a.txt  b.txt  c.txt
[root@PC1 test]# for i in $(find *); do mv $i ${i%.*}; done   ## 利用循环实现
[root@PC1 test]# ls
1  2  3  a  b  c

 

003、

[root@PC1 test]# ls
1.csv  2.csv  3.csv  a.txt  b.txt  c.txt                 ## 循环实现
[root@PC1 test]# for i in $(find *); do mv $i $(echo $i | sed 's/.csv$\|.txt$//'); done
[root@PC1 test]# ls
1  2  3  a  b  c

 

004、

[root@PC1 test]# ls
1.csv  2.csv  3.csv  a.txt  b.txt  c.txt                           ## 循环
[root@PC1 test]# for i in $(find *); do mv $i $(echo $i | sed 's/....$//'); done
[root@PC1 test]# ls
1  2  3  a  b  c

 

005、

[root@PC1 test]# ls
1.csv  2.csv  3.csv  a.txt  b.txt  c.txt                ## 循环
[root@PC1 test]# for i in $(find *); do mv $i ${i//.*/}; done
[root@PC1 test]# ls
1  2  3  a  b  c

 

 

参考:https://www.cnblogs.com/xiami-xm/p/11253215.html

 

posted @   小鲨鱼2018  阅读(621)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-05-13 R语言中prod()、cumprod()函数
2022-05-13 R语言中range函数
2022-05-13 R语言中滞后差分 diff()函数
2022-05-13 R语言中set.seed函数的作用
2022-05-13 R语言中pmin、pmax函数
点击右上角即可分享
微信分享提示