Linux利用sed批量修改文件名
发布时间:2020-12-14 02:02:34 所属栏目:Linux 来源:网络整理
导读:初始文件名 # ls -lh total 5.5G-rw-r--r-- 1 root root 193K Sep 28 09:38 20180908.txtdrwxr-xr-x 2 root root 4.0K Mar 7 16:37 batch-rw-r--r-- 1 root root 160M Mar 13 16:35 batch_dispatcher.log.1-rw-r--r-- 1 root root 17M Jan 8 12:00 batch_gen
初始文件名
# ls -lh total 5.5G -rw-r--r-- 1 root root 193K Sep 28 09:38 20180908.txt drwxr-xr-x 2 root root 4.0K Mar 7 16:37 batch -rw-r--r-- 1 root root 160M Mar 13 16:35 batch_dispatcher.log.1 -rw-r--r-- 1 root root 17M Jan 8 12:00 batch_gen_scheduler.log.1 -rw-r--r-- 1 root root 3.5G Mar 13 16:36 batch_scheduler.log.1 -rw-r--r-- 1 root root 329M Jan 25 10:11 batch_scheduler_test.log.1 drwxr-xr-x 2 root root 4.0K Jan 21 13:54 batch_test -rw-r--r-- 1 root root 30M Jan 25 10:10 batch_test_dispatcher.log.1 -rw-r--r-- 1 root root 137M Mar 13 16:29 boss_bi_access.log.1 -rw-r--r-- 1 root root 86M Mar 13 16:29 boss_bi_error.log.1 -rw-r--r-- 1 root root 185M Mar 13 14:32 boss_channel_access.log.1 -rw-r--r-- 1 root root 96M Mar 13 14:32 boss_channel_error.log.1 -rw-r--r-- 1 root root 77K Jan 21 14:45 monitor_once.log.1 -rw-r--r-- 1 root root 638M Mar 13 16:35 monitor_scheduler.log.1 -rw-r--r-- 1 root root 26M Dec 10 22:00 yqb_job.log.1 drwxr-xr-x 2 root root 4.0K May 29 2018 zhongcai -rw-r--r-- 1 root root 348M Mar 13 16:35 zhongcai_scheduler.log.1 -rw-r--r-- 1 root root 688K Jan 28 10:51 zhongcai_test_access.log.1 -rw-r--r-- 1 root root 538K Jan 29 11:23 zhongcai_test_error.log.1 drwxr-xr-x 2 root root 4.0K Aug 21 2018 zhongcai_v1.4 需要将.log.1结尾的文件更改为.log # for file in $(ls -lh | awk ‘$NF~/log/{print $NF}‘);do newfile=$(echo $file | sed ‘s/.1//g‘); mv $file $newfile; done # 美化一下 for file in $(ls -lh | awk ‘$NF~/log/{print $NF}‘); do newfile=$(echo $file | sed ‘s/.1//g‘) mv $file $newfile done 法二: # ls *.1 | sed -r "s#(.*).1#mv & 1#" | bash 注: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何将Linux密钥从/ dev / input / event *转换为ASCII
- Linux上的C语言中的POSIX线程和全局变量
- LINUX入门:CentOS 7 配置本地yum 源
- linux – 如何在大型代码库中运行ctags?
- linux – Meltdown&Spectre – 修补未修补的虚拟机管理
- LINUX教学:CentOS7下LVM的简单创建
- linux – 没有root的Datastax Cassandra
- linux – 如何在服务器的第一个插槽中识别磁盘名称?
- 如何在linux下的目录下对所有文件执行“du”操作?
- 使用符号| \u0026\u0026?和?在capability.h文件中