LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-17-2009, 11:52 AM   #1
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Rep: Reputation: 15
mass renaming in order


Hey all,

I have a folder with 3000 image files that need to be made into a movie. I want to get rid of 90% off them, since they are not needed. Right now I have:

mov0001.png
mov0002.png
mov0003.png
etc.

I can remove 90% of them with the command

rm ./mov???[123456789].png

which will keep only files ending in 0. However, the movie program needs files names in order to work. How can I rename all the remaining files back to

mov0001.png
mov0002.png
mov0003.png
etc

in order?

Is there a (relatively) simple command I can use?

Thanks
 
Old 06-17-2009, 11:55 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Well, there's the
rename
command, with somewhat unusual syntax, but it can be useful in your case.
 
Old 06-17-2009, 11:57 AM   #3
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Original Poster
Rep: Reputation: 15
Could you give me some more details? I am new to linux. I have seen a few references to the rename command, but am as yet unsure what format strong I would need to recognize the files I am looking for.

I would need to rename

mov0010
mov0020
mov0030
mov0040
etc

to

mov0001
mov0002
mov0003
mov0004

etc
 
Old 06-17-2009, 11:59 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If you list them, they should be already sorted by name, so that you can do a simple loop:
Code:
count=0
for file in *.png
do
  ((count++))
  echo mv $file mov$(printf "%04d" $count).png
done
The echo command is just for safety. Test it as is and the mv command will be simply echoed without actually being executed. Check the result, then remove the echo command and run again.

Last edited by colucix; 06-17-2009 at 12:00 PM. Reason: corrected the printf format string
 
Old 06-17-2009, 12:02 PM   #5
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Original Poster
Rep: Reputation: 15
Cool thanks

time to learn shell scripting I think
 
Old 06-17-2009, 12:02 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

Welcome to LQ.

Code:
#!/bin/bash
count=1
for i in *
do
  name=$( printf "mov%.4d.png" $count )
  mv "$i" "$name"
  count=$(( $count + 1 ))
done
Should work.


Cheers,
Tink


P.S.: Heh ... toooooo slow.

Last edited by Tinkster; 06-17-2009 at 12:04 PM.
 
  


Reply



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
Mass renaming? yanik Linux - General 6 02-16-2009 03:25 PM
mass renaming script frieza Programming 25 12-10-2007 03:56 AM
mass renaming icons for use with XFE? Mr_Shameless Linux - Software 2 06-02-2007 05:55 AM
mass mp3 directory renaming schbond Linux - General 4 01-05-2007 11:18 AM
a question about renaming files in mass! zeltak Linux - Software 1 05-24-2006 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:30 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