Red Hat Topics - file renaming

This is Interesting: Free IT Magazines  
Home > Archive > Red Hat Topics > October 2004 > file renaming





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author file renaming
paul

2004-10-27, 7:45 am

I am looking for an automated way to rename files. I shoot two hundred or
so pictures at my son's basketball games. After editing and deleting I am
looking for a program that will rename a large number of files.

thanks

Paul


----== Posted via webservertalk.com - Unlimited-Uncensored-Secure Usenet News==----
http://www.webservertalk.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Scott Lurndal

2004-10-27, 5:45 pm

paul <paulbon@polarcomm.com> writes:
>I am looking for an automated way to rename files. I shoot two hundred or
>so pictures at my son's basketball games. After editing and deleting I am
>looking for a program that will rename a large number of files.
>
>thanks
>
>Paul
>


A pretty general request. What criteria do you wish to apply to the
original name to determine the new name?

If the criteria are general (i.e. replace prefix A with prefix B), you
can do that with a pretty simple shell script.

For example: Your original names are of the form P0812xxxx.JPG where
xxxx is an ascending integer sequence monotonically increasing from zero;
this script will replace the "P0812" part with "yosemite_aug12_" where
P08120001.JPG will become yosemite_aug12_0001.JPG.

#!/bin/ksh
#

prefix=${1:-P}
newprefix=${2:-P}
suffix=${3:-.JPG}

for file in ${prefix}*${suffix}
do
mv ${file} ${newprefix}${file##${prefix}}
done


====

chmod +x your script then:

scriptname p101 aug_01_ .jpg

will rename all files starting with p101 and ending with .jpg in the
current working directory to begin with aug_01_.

(e.g. p1010001.jpg becomes aug_01_0001.jpg)

(if you don't have the korn shell installed, change the first
line of the script to #!/bin/bash).
Paul Lutus

2004-10-27, 5:45 pm

paul wrote:

> I am looking for an automated way to rename files. I shoot two hundred or
> so pictures at my son's basketball games. After editing and deleting I am
> looking for a program that will rename a large number of files.


You don't say how you want to rename them, and you don't say what kind of
files they are. Here is the basic idea:

#!/bin/sh

# enter the correct suffix below

suffix=jpg

n=0
for fn in *
do
mv $fn $n.$suffix
((n++))
done

--
Paul Lutus
http://www.arachnoid.com

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com