Copying List of Files Under Different File Names ?!

Hi to all here ,

Excuse me for the lamer question but I need UNIX command for copying List of Files Under Different File Names !

for example I have this list:

new_001.jpg
new_002.jpg
new_003.jpg
.....

I want to copy all files that start with "new_" to the same directory but under new names that starts with "old_"

for example:

old_001.jpg
old_002.jpg
old_003.jpg

Is there any simple command for that or I need special script ?

Thank you all in advance :b:

Try this, maybe there is an easier way, but at the moment here is what should work, hoping you are on some linux flavor, if not, then let me know what flavor of UNIX are you on, we may have to modify /bin/ksh to /usr/bin/ksh or wherever ksh is on your UNIX variant.

Put the the list of new* names in a file called /tmp/list. Put the below code in /tmp/script.sh and chmod +x /tmp/script.sh

Run the script in the directory where you have the new* files by running the script as /tmp/script.sh, when you run the script, it will echo out the moves/renames, if you like what you see, remove the echo in front of the mv, and then run it.

#!/bin/ksh
for i in `cat /tmp/list`
do
A=`echo $i|awk -F"_" '{print $2}'`
echo "mv $i old_$A"
done

Hi,

Try:

$ for image in *.jpg; do cp "$image" "${image/new/old}"; done

Regards,
Birei

Thank you guys !

The problem is that the command must be executed through php shell (passthru) ...
The files are in specific path: /home/sitename.com/www/photos/

so how must look your command indicating the specific path ?

thank you all!

modifying the above from birei to account for path:

$ for image in /home/sitename.com/www/photos/*.jpg; do cp "$image" "${image/new/old}"; done

I already tried this ! doesn`t work ...:frowning:

whats the error?

don`t know but the files aren`t copied ...

for now this works for me:

 
cp /home/sitename.com/www/photos/new_*.jpg /home/sitename.com/www/photos_old/

copying files in different directory under the same names ....