Copying List of Files Under Different File Names ?!

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying List of Files Under Different File Names ?!
# 1  
Old 08-14-2011
Question 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:


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

for example:


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

Thank you all in advance Smilie

Last edited by zxmaus; 08-14-2011 at 01:15 PM..
# 2  
Old 08-14-2011
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/ and chmod +x /tmp/

Run the script in the directory where you have the new* files by running the script as /tmp/, 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.

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

# 3  
Old 08-14-2011

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

# 4  
Old 08-14-2011

Originally Posted by birei

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


Thank you guys !

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

so how must look your command indicating the specific path ?

thank you all!

Last edited by boboweb_; 08-14-2011 at 02:16 PM..
# 5  
Old 08-14-2011
modifying the above from birei to account for path:

$ for image in /home/*.jpg; do cp "$image" "${image/new/old}"; done
# 6  
Old 08-14-2011
CPU & Memory

Originally Posted by dude2cool
modifying the above from birei to account for path:

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

I already tried this ! doesn`t work ...Smilie
# 7  
Old 08-14-2011
whats the error?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to list files names and sizes in a directory and output result to the file?

Hi , I'm trying to list the files and output is written to a file. But when I execute the command , the output file is being listed. How to exclude it ? /tmp file1.txt file2.txt ls -ltr |grep -v '-' | awk print {$9, $5} > output.txt cat output.txt file1.txt file2.txt output.txt (8 Replies)
Discussion started by: etldeveloper
8 Replies

2. Shell Programming and Scripting

Finding a string in a list of files, print file names

I'm interested in writing a report script using BASH that searches all of the files in a particular directory for a keyword and printing a list of files containing this string... In fact this reporting script would have searches for multiple keywords, so I'm interested in making multiple... (2 Replies)
Discussion started by: chemscripter904
2 Replies

3. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

4. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

5. Shell Programming and Scripting

Inserting text in file names while copying them.

I'm trying to find a Bourne shell script that will copy files from one directory using a wild card for the file name (*) and add some more characters in the middle of the file name as it is copied. As an example: /u01/tmp-file1.xml => /u02/tmp-file1-20130620.xml /u01/tmp-file2.xml => ... (6 Replies)
Discussion started by: Tony Keller
6 Replies

6. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

7. UNIX for Dummies Questions & Answers

copying same file multiple times with different names

hi, I am copying a file from 1 folder to another in /bin/sh. if the file already exists there, it should get copied as filename1. again if copying next time it shouldget copied as filename2.. , on.. The problem is i am able to get uptil filename1.. but how do i know what... (6 Replies)
Discussion started by: blackcat
6 Replies

8. UNIX for Dummies Questions & Answers

Copying a list of files from one 'server' to another?

I have two servers. I would like to copy some files from one directory on server A into the same directory on server B. Its not all the files in in the directory, just some of them. Is there a way to make a file list in a txt file and then somehow copy all the files in that list in one go to... (6 Replies)
Discussion started by: Sepia
6 Replies

9. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies

10. UNIX for Dummies Questions & Answers

Copying file names returned from a grep command into another directory

When I do the following : grep -l "string" *, I get a list of file names returned. Is there a way to copy the files returned from the list into another directory ?. Thanks. (4 Replies)
Discussion started by: Kartheg
4 Replies
Login or Register to Ask a Question