linux - 使用 bash 脚本更改文件名

标签 linux bash

我有很多文件,我想将这些名称更改为 file_1-1 的文件,直到到达 file_8-5 的 file40。

我编写了这段代码,但它删除了所有文件并将最后一个文件转换为 file1。

    pwd
    for i in {1..8}     
    do
    for j in {1..5}    
    do
    for k in {1..40}    
    do
    (cd ./prof/ && mv file_$i-$j.dat file$k.dat)
    done
    done
    done

最佳答案

我猜你只需要去prof/一次。然后,您可以根据 ij 计算 k。在bash中:

cd prof
for i in {1..8}     
do
    for j in {1..5}    
    do
        k=$(( ($i-1) * 5 + $j ))
        mv pixel_$i-$j.ps pixel$k.ps
    done
done

关于linux - 使用 bash 脚本更改文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57785418/

相关文章:

linux - 将时间转换为纪元时间并找出 2 个时间戳之间的差异

linux - 在目录中一个一个地循环文件,并在屏幕上显示对它们执行命令的结果

linux - 无法更新 iceauthority 文件/var/lib/gdm/.iceauthority

linux - 如何获取长时间运行的 Linux 进程的启动时间?

php - 使用 Symfony Process 解析命令行输出

regex - sed ubuntu vs mac 正则表达式

java - 连续运行shell脚本时JVM进入休眠状态

ios - Xcode "arpa/telnet.h"文件未找到

linux - 平台驱动有什么用?

regex - 我怎样才能在 bash 中正确地转义这个正则表达式?