linux - 在Linux中修改多个文件名的快速方法

标签 linux command-line filenames

我有文件:

1.pgm ... 400.pgm 从 1 到 400 的连续数字,格式相同。

我想将它们复制到:

401.pgm ... 800.pgm,这基本上是因为我需要更多输入数据

我想知道在 Linux 中是否有快速的方法来做到这一点?

最佳答案

如果您的文件具有此结构,则只需:

for file in *.pgm ; do
   num=${file%%.pgm}
   newnum=$(( $num + 400 ))  #more portable than 'let', thx to @user2719058 for the reminder!
   echo mv "${file}" "${newnum}.pgm"
done

一旦你确信这能达到你想要的效果,就取出echo...

关于linux - 在Linux中修改多个文件名的快速方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20383372/

相关文章:

linux - Debian、make-kpkg 和 Linux 内核开发

java - guice:在命令行运行时注入(inject)/绑定(bind)

linux - 递归模式下的 Wget 输出

windows - for/f 循环处理文件名和符号

VB6:CreateFile() 在当前工作目录中创建名称乱码的文件

c++ - 为什么 if (fork() == 0) { getpid() } 和 popen() 进程返回相同的进程 ID?

linux - 启动时在 Linux 下运行 ASP.NET Core 应用程序

windows - 如何在 Perl 中编写 *filename* 包含 utf8 字符的文件?

linux - 如何将 'stdout' 重定向到 'stderr' 并将 'stderr' 重定向到 'stdout'?

windows - 命令行参数,解析的标准方法?