夔牛犇犇 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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器