夔牛犇犇 2019-03-15 15:53 采纳率: 100%
浏览 1212
已采纳

如何批量修改数字文件名

现在有以数字命名的文件如下:
-rw-r--r-- 1 root root 0 Mar 15 15:45 12.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 13.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 14.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 15.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 16.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 17.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 18.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 19.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 1.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 2.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 3.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 4.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 5.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 6.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 7.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 8.txt
-rw-r--r-- 1 root root 0 Mar 15 15:45 9.txt

想将所有文件重新命名,就是在原来的文件名前加一个a变成a1.txt这类的,
如果在数字连续的情况下,可以用FOR循环来实现:

[root@centos_7_1 dd]# i=1; for x in *; do mv $x a$i.txt;let i=i+1; done

但是现在数字文件名不连续,该怎么做?

  • 写回答

2条回答 默认 最新

  • mkchiny 2019-03-15 16:03
    关注
    #!/bin/bash
    
    for file in `ls`
    do
        mv ${file} a${file}
    done
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素