LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-01-2005, 04:24 PM   #1
maginotjr
Member
 
Registered: Aug 2004
Location: BR - Floripa
Distribution: Ubuntu 9.10 - 2.6.x.x
Posts: 661

Rep: Reputation: 35
Renaming multple files....


The problem may be simple for some but for me is giving me with less hair....

I have some JPG files that I took from my Palm, but all they are named as Set01_02.jpg and so on, and I want to rename them to something like Maginot-01.jpg...

I have tried rename command but I cant figure out how it works exactly... I have searched in google and found some for in scripts and in the end nothing realy helped me... so Im asking here for those who understand how to do this to help me with the right script, the right syntax for rename or maybe some miraculous program that makes rename multiple files an easy job on linux...


[ ]ś regards
 
Old 10-01-2005, 04:37 PM   #2
egag
Senior Member
 
Registered: Jul 2004
Location: Netherlands
Distribution: Slackware
Posts: 2,721

Rep: Reputation: 53
did you see the man page ?

it's like :
rename <existing-part-of-name> <replacenment-part-of-name> <target-files>

can you give an example of what you want to do ?

egag
 
Old 10-01-2005, 04:45 PM   #3
phunkymunky
Member
 
Registered: Aug 2003
Location: Glasgow, Scotland
Distribution: Slackware 14.0, Debian 7.0
Posts: 60

Rep: Reputation: 22
I looked for something like this too, all the picture from my camera were dscn000234.jpg etc and wanted to rename them something meaningful. Ended up writing a small script (see below).

I put all my pics in a temp directiry along with the script (called rename.sh) and then just call it with the new name I want, from your post it would be
Code:
rename.sh Maginot-
, this would result in files called Maginot-1.jpg ,Maginot-2.jpg ......Maginot-XX.jpg.
Notice I put in the hyphen (-) at the end otherwise they would come out as Maginot1.jpg etc

Only works on jpegs but could be modified for any file extension.

Hope this helps, it has saved me loads of time.

This is probably pretty crap code but it works for me feel free to change it if you want to.

Code:
#!/bin/bash

#renames camera files from camera numbered (123456.jpg) to something relevant.

n=0
for filename in *.jpg
#count  jpg files in directory
do
  let "n=n+1"
done
echo "$n jpgs in directory"

x=1
for filename in *.jpg
do
  echo "$filename changed to " 
  mv $filename $1$x.jpg
  echo $1$x.jpg
  let "x=x+1"
done

exit 0
 
Old 10-01-2005, 05:02 PM   #4
maginotjr
Member
 
Registered: Aug 2004
Location: BR - Floripa
Distribution: Ubuntu 9.10 - 2.6.x.x
Posts: 661

Original Poster
Rep: Reputation: 35
Quote:
did you see the man page ?

it's like :
rename <existing-part-of-name> <replacenment-part-of-name> <target-files>
In the man page isnt so easy to understand as you put here ... lol I will try the way you say....

Quote:

This is probably pretty crap code but it works for me feel free to change it if you want to.
I think its pretty good... and the very important is that works! Thanks!


regards [ ]'s
 
Old 06-04-2006, 11:09 AM   #5
Megamieuwsel
Member
 
Registered: Sep 2002
Location: Haarlem , the Netherlands
Distribution: VectorLinux SOHO 5.1
Posts: 470

Rep: Reputation: 35
I like that little script as well , but....
Would it be possible to make it so , the output would start with (for example) "Tabby-0001.jpg" instead of "Tabby-1.jpg"?
I mean : Right now , doing an "ls" shows me something like : Tabby-1.jpg , Tabby-10.jpg , Tabby-100.jpg , Tabby-101.jpg , Tabby-102.jpg , etc...
Then it does the same with "2" , resulting in : Tabby-199.jpg , Tabby-2.jpg , Tabby-20.jpg , Tabby-200.jpg , Tabby-201.jpg , etc

In a strictly CLI , this wouldn't be much of an issue , but when you're browsing such a dir by means of a graphical app (Like Rox-filer or Konqueror) any series you have aren't properly lined up.

I can't script my ass out of a wet paper bag myself , but shouldn't there be a part in that script that creates some kind of place-holders , based on the number of files , counted in the first part?
I mean : The script counts the number of files and the result is somewhere in the three digits.
Placeholders for three-digit numbers are included/created and then the renaming of the files utilises these placeholders , so the output would be like:
Code:
Tabby-001.jpg
Tabby-002.jpg
Tabby-003.jpg
Tabby-004.jpg
Tabby-005.jpg
.
.
.

Tabby-010.jpg
Tabby-011.jpg
Tabby-012.jpg
Tabby-013.jpg
Tabby-014.jpg
...etc
Anyone up for it?

Last edited by Megamieuwsel; 06-04-2006 at 11:11 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
renaming multiple files linuxhippy Slackware 10 01-21-2011 02:53 AM
bash help renaming files kahn Programming 6 06-16-2005 08:15 AM
Renaming lots of files Tuttle Linux - General 4 11-18-2004 12:15 PM
renaming files script. xushi Programming 4 10-10-2004 09:06 AM
Renaming files in one go anon318 Linux - Software 1 01-12-2004 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration