gpt4 book ai didi

linux - 使用 bash 为文件添加文件扩展名

转载 作者:IT老高 更新时间:2023-10-28 12:25:23 25 4
gpt4 key购买 nike

使用 bash 将文件扩展名“.jpg”添加到无扩展名文件的好方法是什么?

最佳答案

# Strip .jpg from all filenames
for f in *.jpg; do mv "$f" "${f%.jpg}"; done
# Add .jpg to all filenames (even those with .jpg already)
for f in *; do mv "$f" "$f.jpg"; done
# Add .jpg to all filenames...unless they are already .jpg
for f in *; do case "$f" in *.jpg) echo skipped $f;; *) mv "$f" "$f".jpg; esac; done
# Add .jpg to all filenames...unless they already have a . extension
for f in *; do case "$f" in *.*) echo skipped $f;; *) mv "$f" "$f".jpg; esac; done

关于linux - 使用 bash 为文件添加文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6114004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com