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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers copying a pattern of files in one directory into other with new pattern names...
# 1  
Old 12-14-2008
Question 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
..
.
abcxyz_bkp

Can any one please suggest me?

Thanks and Regards
# 2  
Old 12-14-2008
this should do it.

Code:
find /path -name abc\* -exec cp -p {} /path1/{}_bkp \;

# 3  
Old 12-14-2008
Hi frank rizzo,

Thank you for repliying. I am getting the following error:

$ find /home/../ -name abc\* -exec cp -p {} /home/.../backup/{}_bkp \;
cp: 0653-436 /home/.../backup is a directory.
Specify -r or -R to copy.


So, I just tried doing this:

$ find /home/../ -name abc\* -exec cp -p -R {} /home/.../backup/{}_bkp \;
cp: 0653-437 /home/.../backup/{}_bkp is not a directory.

I donot understand what to do.
# 4  
Old 12-14-2008
why do you have 3 dots in your path? Try it using full paths.
# 5  
Old 12-14-2008
I am sorry to confuse you with dots (...). I actually removed the path and place the dots. But now I replace the path and give here as it appears.

$ find /home/rajesh/data/ -name abc\* -exec cp -p {} /home/rajesh/backup/{}_bkp \;
cp: 0653-436 /home/rajesh/backup is a directory.
Specify -r or -R to copy.


So, I just tried doing this:

$ find /home/rajesh/data/ -name abc\* -exec cp -p -R {} /home/rajesh/backup/{}_bkp \;
cp: 0653-437 /home/rakesh/backup/{}_bkp is not a directory.


Please suggest.

Thanks and Regards
# 6  
Old 12-15-2008
For me it works perfectly fine.

find . -name "arr*" -exec cp -p {} //ms/user/s/sibasha/tmp1/{}_bkp \;
# 7  
Old 12-15-2008
Hey... Its strange.

Initially, I got the same error when I used both the script suggested by frank_rizzo and siba.s.nayak.

Later, I dont know how but when I tried after a while both the ways suggested by frank_rizzo and siba.s.nayak are not giving any error. But in the target directory only one file is getting created with the name {}_bkp.

I am using same script as above.

$ find /home/rajesh/data/ -name abc\* -exec cp -p -R {} /home/rajesh/backup/{}_bkp \;
$ find . -name "abc*" -exec cp -p {} //home/rajesh/backup/{}_bkp \;
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. Shell Programming and Scripting

Watch a directory for files with a pecific pattern

I dont know if this possible. I need to watch a directory and if any file gets appeneded with a particular entry say, nologin.php, we should get output of that. (1 Reply)
Discussion started by: anil510
1 Replies

3. Shell Programming and Scripting

Copying files with a specific pattern

Hi All I am trying to copy files from one location to another and given below are some sample ones: aaa_bbb_ccc_ddd_cost_code_20140330.gz aaa_bbb_ccc_ddd_revenue_zone_20140329.gz aaa_bbb_ccc_ddd_benefit_extract_20140330.csv.gz aaa_bbb_ccc_ddd_profit_zone_20150509.csv.gz... (17 Replies)
Discussion started by: swasid
17 Replies

4. Shell Programming and Scripting

Remove all files except the subdirectory(without pattern) in a directory

I used rm * and it deleted the files in the directory but gives and error message for unsuccessful subdirectory deletion. "rm: cannot remove 'DirectoryName': Is a directory" I dont want to explicitly get the above error. What are the modifications I have to do in the rm command? (3 Replies)
Discussion started by: duplicate
3 Replies

5. Shell Programming and Scripting

Copying files based on a pattern

Hi All, I need to find and list the last 5 days files in that exact name with "MIM" and copy to another directory. please help me in this there is around 30000 files Thanks Murali (7 Replies)
Discussion started by: 969murali@gmail
7 Replies

6. Shell Programming and Scripting

How to find files in a pattern directory?

Hi, I have more than 1000 directories under one directory (lets says under /home/). Sub directories are like A1 to A100,B1 to B100 etc.. Here my problem is I need to find the files older than 10 days in the directories which starts with A*. I tried some thing like this which is not... (2 Replies)
Discussion started by: shhrikanth
2 Replies

7. UNIX for Dummies Questions & Answers

find the file names having specified pattern at specified position in the current directory

I would need a command for finding first 15000 of the file names whose 25th postion is 5 in the current directory alone. I do have this painful command find . -name '5*' | head -15000 | cut -c3- please refine this. Of course the above command also searches in the sub directories... (3 Replies)
Discussion started by: vk39221
3 Replies

8. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

9. Solaris

Look for distinct files under a directory matching a pattern

Hi, I'm searching for a pattern 'java' under a directory but it is returning all the files containing 'java', but I want to have only distinct files not all. please help (2 Replies)
Discussion started by: b.paramanatti
2 Replies

10. Shell Programming and Scripting

Counting files in a directory that match a pattern

I have 20 files in a direcotry like BARE01_DLY_MKT_YYYYMMDD. The MKT differes for all these files but the remaining syntax remains the same for a particular day. If I am checking for today I need to make sure that there are 20 files that start with BARE01_DLY_MKT_20060720. How can I write a... (31 Replies)
Discussion started by: dsravan
31 Replies
Login or Register to Ask a Question