简体   繁体   中英

renaming file using shell script

I have tons of image inside a folder and it also has different file types. I have tried googling for an answer but I can't seem to find one. I wanted the files to be named 1.jpg, 2.png, 3.gif. . . n.JPEG. Could someone help me out with this?

Try the command below:

cd path_to_your_files
declare -i i=0; for f in *; do i=$((i+1));fn=$i".${f##*.}"; mv "$f" "$fn"; done

Make note that the command above is a bash script.

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