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

使用 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

https://stackoverflow.com/questions/6114004/

相关文章:

python - 访问对象内存地址

windows - 如何确定特定文件是否在 Windows 中打开?

python - Python 的 List 是如何实现的?

linux - 使用 find 命令但排除两个目录中的文件

linux - 如何使用 cURL 从 GitHub 下载 tarball?

python - 仅在 Django 启动 ONCE 时执行代码?

python - linux tee 不能与 python 一起使用?

python - 如何使用 pandas 读取大型 csv 文件?

python - 如何在被调用的方法中获取调用者的方法名?

python - 在 Python 中使用多个参数进行字符串格式化(例如 '%s ... %s' )