Script to search and copy files


 
Thread Tools Search this Thread
# 1  
Script to search and copy files

HI everyone,

I been to this site before for help and found my answers on other threads now I am posting my own Smilie.

I have a list of file names with out extensions on an txt file. I need a way for the script to search on the server for each file name and copy the files over to a new directory. Does anyone know how to?

I tried running
xargs -a gold.txt cp /path/directoy/ but i got an error.
I know this is close to what I need but i know it will ask for path of each file which I don't have. I would really appreciate the help. Thank you.
# 2  
Code:
cat gold.txt | while read FILE_NME
do
    FL_NME_PATH=`find / -type f -name "$FILE_NME" `
    
    cp $FILE_NME_PATH /path/directory/
done

# 3  
cp can be done in find's exec clause, also "cat" is not needed:
Code:
while read FILE; do
  find / -name "$FILE" -type f -exec cp {} /path/directory/ \;
done < gold.txt

# 4  
I am running it right now thank you. But the file names don't have extensions. inside the .txt file the names are like ER3021 but I need to find file ER3021.jpg or .gif will that work?
# 5  
Nope. For that to work use this:
Code:
while read FILE; do
  find / -name "$FILE.*" -type f -exec cp {} /path/directory/ \;
done < gold.txt

# 6  
now sorry to be a bother but last thing. Can I specify where to search? like I want it to search inside folder /home/neigroup/files/ instead of the whole server.
# 7  
Code:
while read FILE; do
  find /home/neigroup/files/ -name "$FILE.*" -type f -exec cp {} /path/directory/ \;
done < gold.txt

 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #572
Difficulty: Easy
For most programming languages, array indices start at zero. This is known as zero-indexing.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and Copy Files

Hi All Need your help, I am looking for a script to search for files with specific extension as .log and then copy the latest one to a different folder. Here is the scenario /dev/abc/xyz/a_2_122920131.log /dev/abc/xyz/a_2_123020131.log /dev/abc/xyz/b_2_12302013.log... (2 Replies)
Discussion started by: jimmun
2 Replies

2. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

3. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

4. Shell Programming and Scripting

Copy Files with script

Hello, I have written a script to copy files from one partion to another. Not sure if this is correct. #!/bin/sh CDR_SOURCE=/storage/archive/logmgmt/result/billing/ CDR_DEST=/storage4/archive/logmgmt/result/billing/ cp $CDR_SOURCE $CDR_DEST; exit 0 The CDR_SOURCE folder has... (5 Replies)
Discussion started by: Siddheshk
5 Replies

5. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

6. Shell Programming and Scripting

Search and Copy Script

Dear All, I would like to create a Unix script which basically searches for files which are more than 2 days old and copy only the new files to the destination. What i mean is if the destination may have most of the files, it may not have only last 2 to 3 days file. I am able to create the... (6 Replies)
Discussion started by: rrb2009
6 Replies

7. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

8. Shell Programming and Scripting

shell script to search and copy files

Hello Im new to this forums, I would like some help regarding a script that I need in order to copy some files. Heres the scenario: I need to search several files which have a particular code inside, lets say "test" all of them on different directories. I need to copy all of them on a new... (4 Replies)
Discussion started by: c.watson
4 Replies

9. Shell Programming and Scripting

search files and copy them to a directory with datestamp attacched to it

Hi I need to search the some ftp files created in last 24 hours and copy them to a directory with date stamp attached to it. Iam using following command to search the files find $CA_OUT_PATH/*/ftp_out -type f -mtime -1 but now how to copy these files to some other directory one by one ... (1 Reply)
Discussion started by: sreenusola
1 Replies

10. UNIX for Dummies Questions & Answers

search files and copy them to a directory with datestamp attached to it

Hi I need to search the some ftp files created in last 24 hours and copy them to a directory with date stamp attached to it. Iam using following command to search the files find $CA_OUT_PATH/*/ftp_out -type f -mtime -1 but now how to copy these files to some other directory one by one with... (1 Reply)
Discussion started by: sreenusola
1 Replies

Featured Tech Videos