Replace all files with a certain filename with another file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace all files with a certain filename with another file
# 1  
Old 06-30-2008
Question Replace all files with a certain filename with another file

I tried searching for this, but I might have used the wrong terms as I couldn't find answers to this question.

I'm looking for a way to replace all files with a certain filename with another file within a specific directory including all of it's subdirectory using a shell-script.
# 2  
Old 06-30-2008
Code:
find /path/to/files -name certainfilename |\
while read filename
do
     cp /path/to/anotherfilename $filename
done

This may change ownership and protections on those files copied in. This could be a bad thing.
# 3  
Old 06-30-2008
Question Thank you!

Thank you!

Will this code cause any issues if runned on one account (inside folders where there is only one owner)? In this case it would maybe be a good idea to simply copy the permissions as well?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find all .sh files in file system and need to replace the string inside .sh files

Hi All, I need to write a script to find all "*.sh" files in /home file system and if any string find "*.sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this. find / -name... (3 Replies)
Discussion started by: bhas85
3 Replies

2. UNIX for Beginners Questions & Answers

Renaming files by appending string from within file to filename

Greetings. I am working in a Linux environment and am trying to figure out a way to rename files in a directory by appending a unique strings that appears within a certain area in those files. I have gotten as far as identifying what that particular unique string is with a command like the... (10 Replies)
Discussion started by: HLee1981
10 Replies

3. Shell Programming and Scripting

Read each line in fileA, replace in all files with matching filename

Hello, I supposed that I asked the similar question but I could not have found it when I search on our forum. EXYU+: EXYU%3A+HRT+1 EXYU%3A+HRT+2 EXYU%3A+HRT+3 EXYU_url: #SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7777.ts #SERVICE... (2 Replies)
Discussion started by: baris35
2 Replies

4. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

5. UNIX for Dummies Questions & Answers

To replace a filename

Hi i want to replace date stamp filename to original file name. i want to remove the datestamp after .txt For eg: file_name.txt_01-1002014 output: file_name.txt tried with below one but not able to achieve mv file_name.txt_01-1002014`basename "file_name.txt_01-1002014 "`.txt (4 Replies)
Discussion started by: rohit_shinez
4 Replies

6. Shell Programming and Scripting

Adding filename and line number from multiple files to final file

Hi all, I have 20 files (file001.txt upto file020.txt) and I want to read them from 3rd line upto end of file (line 1002). But in the final file they should appear to start from line 1. I need following kind of output in a single file: Filename Line number 2ndcolumn 4thcolumn I... (14 Replies)
Discussion started by: bioinfo
14 Replies

7. Shell Programming and Scripting

Merge CSV files and create a column with the filename from the original file

Hello everyone!! I am not completely new to shell script but I havent been able to find the answer to my problem and I'm sure there are some smart brains here up for the challenge :D. I have several CSV files that I need to combine into one, but I also need to know where each row came from.... (7 Replies)
Discussion started by: fransanchezoria
7 Replies

8. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

9. Shell Programming and Scripting

joining multiple files into one while putting the filename in the file

Hello, I know how to join multiple files using the cat function. I want to do something a little more advanced. Basically I want to put the filename in the first column... One thing to note is that the file is tab delimited. e.g. file1.txt joe 1 4 5 6 7 3 manny 2 3 4 5 6 7 ... (4 Replies)
Discussion started by: phil_heath
4 Replies

10. Shell Programming and Scripting

Replace text with filename

Hi, I have a few thousand files, each contains the word "hello". Would it be possible to do a batch job that replaces the word hello with the filename? Thanks. (2 Replies)
Discussion started by: calrog
2 Replies
Login or Register to Ask a Question