ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I've got a number of photos that need changing their names.
What I need is a short script to change the names to 01.jpg, 02.jpg, etc.
I've been trying to do it with 'rename' and 'move' but I can't get it right.
Also, I've started learning python, and am courious how it would look in python.
loop=1;
#!/bin/sh
IFS='
'
for FILE in `ls -t -r zdjecia`;
do
#Get file extension
EXTENSION=`echo $FILE | sed 's/.*[.]//g'`
NEW_NAME=`$loop.$EXTENSION`
let loop++;
mv zdjecia/$FILE zdjecia/$NEW_NAME
done
Code:
mv: `zdjecia/dsc_0546.jpg' and `zdjecia/dsc_0546.jpg' are the same file
./skrypt: line 13: 65.jpg: command not found
mv: `zdjecia/dsc_0545.jpg' and `zdjecia/dsc_0545.jpg' are the same file
./skrypt: line 13: 66.jpg: command not found
mv: `zdjecia/dsc_0542.jpg' and `zdjecia/dsc_0542.jpg' are the same file
./skrypt: line 13: 67.jpg: command not found
mv: `zdjecia/dsc_0539.jpg' and `zdjecia/dsc_0539.jpg' are the same file
./skrypt: line 13: 68.jpg: command not found
mv: `zdjecia/dsc_0498a.jpg' and `zdjecia/dsc_0498a.jpg' are the same file
./skrypt: line 13: 69.jpg: command not found
mv: `zdjecia/dsc_0438.jpg' and `zdjecia/dsc_0438.jpg' are the same file
./skrypt: line 13: 70.jpg: command not found
mv: `zdjecia/dsc_0420.jpg' and `zdjecia/dsc_0420.jpg' are the same file
./skrypt: line 13: 71.jpg: command not found
mv: `zdjecia/dsc_0419.jpg' and `zdjecia/dsc_0419.jpg' are the same file
./skrypt: line 13: 72.jpg: command not found
mv: `zdjecia/dsc_0417.jpg' and `zdjecia/dsc_0417.jpg' are the same file
./skrypt: line 13: 73.jpg: command not found
mv: `zdjecia/dsc_0982.jpg' and `zdjecia/dsc_0982.jpg' are the same file
Also, I've started learning python, and am courious how it would look in python.
Code:
import os
os.chdir("where")
for num,files in enumerate(glob.glob("*.jpg")):
s=os.path.splitext(files)
fname,ext=s[0],s[1]
if num +1 < 10: n=str(num+1).zfill(2)
os.rename(files,s[0]+str(n)+s[1])
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.