简体   繁体   中英

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      

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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