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 all, i'm having trouble with renaming files.. i have about 700 of them i need to rename =/ But in 2 parts..
1) There are about 150 files all in 1 folder named
Yannis & Joulia 001.jpg 002 003 004..........
I want to get rid of the & sign.. So its just
Yannis Julia 001.jpg 002 003 .........
2) There are 4 folders with pics that have random names such as
dscn0001.jpg
dscn0002.jpg
How can i just make a loop to rename the pics as
001.jpg
002.jpg
003.jpg
and so on?
And can i tell it to start from another number than 000 ? So when i move to the second folder, i can start from, say 100.jpg, 101.jpg.. etc...
I'm not much of a bash programmer, so i have no idea on how i can do this, although i do know enough that it's probably 1 line of code.. hehe
for i in *.jpg
do
mainPart=`echo "$i" | cut -f 1-2 -d '\&'`
mv "$i" "$mainPart"
done
mainPart contains the name of your picture. The cut function allows to do some 'curtting' and you get the field 1 and 2 (-f 1-2) after cutting around the delimiter & (-d '\&').
It should work but maybe the spaces are going to be an issue. Pay attention to that. For the other, you can use the same trick by tuning the cutting part.
cut: the delimiter must be a single character
Try `cut --help' for more information.
mv: cannot move `Yannis & Julia 136_jpg.jpg' to `': No such file or directory
Edit: As for the second part, i'm not sure how this would solve it unless i ad some $var += 1; somewhere
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.