简体   繁体   English

如何使用 Linux 命令将“1.jpg”等文件夹的所有文件重命名为“1 hello.jpg”?

[英]How can I rename all file of a folder like '1.jpg' to '1 hello.jpg' with Linux command?

I have thousands of pictures in a folder like this-我在这样的文件夹中有数千张图片-

1.jpg

2.jpg

3.jpg

And I want to rename them all to我想将它们全部重命名为

   1 hello.jpg

    2 hello.jpg

    3 hello.jpg

Try this:尝试这个:

#!/bin/bash

for x in [[:digit:]]*.jpg;do mv $x "${x%.jpg} hello.jpg";done

This script would be exactly doing what you want.该脚本将完全按照您的意愿行事。

#!/usr/bin/env bash

for f in *.jpg
do
    oldName=$(basename -s.jpg $f)
    mv $f  $oldName\ hello.jpg
done      

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

相关问题 如何删除外壳中除“ 1.jpg”以外的所有jpg文件 - How can I delete all jpg files except “1.jpg” in shell 是否可以将目录中的所有文件重命名为0.jpg,1.jpg,2.jpg等? - Is it possible rename all files in a directory to 0.jpg, 1.jpg, 2.jpg, etc? 如何在linux中重命名包含破折号的所有子目录中的所有.jpg文件? - How to rename all .jpg files in all subdirs which contains dash in linux? Linux,如何将hex文件转换为jpg? - On Linux, how do I convert a hex file to a jpg? 如何移动具有(.JPEG,.JPG,.jpeg,.jpg扩展名)的单个文件,以及如何使用Linux bash将扩展名更改为.jpg - How to move a single file with (.JPEG, .JPG, .jpeg, .jpg) extensions) and change the extension to .jpg with Linux bash 如何在Linux控制台中删除.jpg文件 - How to delete .jpg file in linux console 在Linux上将jpg从文件夹复制到文件夹 - Copy jpg from folder to folder on Linux 如何使用linux命令将jpg文件转换为png文件? + 难度 = 子文件夹 - How to convert jpg files into png files with linux command? + Difficulty = Subfolders 递归重命名所有子目录中的 .jpg 文件 - Recursively rename .jpg files in all subdirectories 如何在Linux OS中将任何文档格式转换为jpg文件 - How to convert any document format to jpg file in linux os
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM