简体   繁体   English

重命名文件并更改扩展名

[英]Renaming file and changing the extension

I have a directory with almost 2000 images and some of them don't have the right extension. 我的目录中包含近2000张图片,其中有些没有正确的扩展名。 And these extensions are formatted like this *.images(xxx) 1 . 这些扩展名的格式如下: *.images(xxx) 1 Is it possible to change the extension to jpg 是否可以将扩展名更改为jpg

UPDATE I have this code but it omits the extension. 更新我有此代码,但它省略了扩展名。

declare -i i=0;
for f in *;
    do
        fn=$i".${f##*.jpg}";
        mv "$f" "/home/vianney/Desktop/IPIP/$fn";
        i=$((i+1));
    done
clear

How could I change this code to display the filetype 如何更改此代码以显示文件类型

This can be done with a for loop: 这可以通过for循环来完成:

#!/bin/sh

for i in *
do mv "${i}" "${i%.*}.jpg"
done

To expand a bit on the issues addressed in the comments below; 进一步讨论以下评论中讨论的问题; here is a variation on the program which appends a sequential numerical suffix to the files as they are processed: 这是程序的一种变体,它在处理文件时将顺序数字后缀附加到文件中:

#!/bin/sh

count=0
for i in *.*
do mv "${i}" "${i%.*}.${count}.jpg"
   count=$((count + 1))
done

I would go with mv and bash oneliner: for file in *.images*; do mv "$file" "${file/\\.*/\\.jpg}"; done; 我将使用mv和bash oneliner: for file in *.images*; do mv "$file" "${file/\\.*/\\.jpg}"; done; for file in *.images*; do mv "$file" "${file/\\.*/\\.jpg}"; done;

Let me know if it helped you? 让我知道它对您有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM