Find and Copy file of specific location


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-26-2015
RedHat Find and Copy file of specific location

Dear All,
I need to transfer all files present in one location to another but those files should be of specific extension like.

Find and copy all files of extension .xls, .pdf, .txt from location usr/tmp to location /per/Treat
# 2  
Old 03-26-2015
Please show what you have tried so far.
# 3  
Old 03-26-2015
RedHat

I tried below 2 things

Code:
ALL_ACC_EXTNS=(dat, txt, pdf)
for i in "${ALL_ACC_EXTNS[@]}"; do
cp ${Source}/*.$i $Destination
done

and second try with
Code:
ACC_EXT=".TXT$|.PDF$|.XLSX$"
find . -name $(echo $AACC_EXT) -type f -exec cp -t '$Destination' {} +

Both didn't work for me.
# 4  
Old 03-26-2015
You could try something like:
Code:
find .....  -name "*.txt" -o -name "*.pdf" -o -name "*.xls*" -exec cp .......

# 5  
Old 03-26-2015
Code:
sudo find . -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} dest_dir \;

or

Code:
cp `find . | egrep "*\.(txt|pdf|xls)"` dest_dir

Find in conjunction with the period(.) will start looking from the current directory and prune the rest of the dirs. Meaning it will look in the cwd you are in. Then when it finds a folder it will look in that folder as well.

Find in conjunction with the forward slash(/) will start looking from the top of your directory tree.

Last edited by codecaine21; 03-26-2015 at 01:22 PM..
# 6  
Old 03-26-2015
RedHat

Actually I wanted to put all Extension in a Variable and then search it.

Code:
like ACC_EXT=".TXT$|.DOC$|.XLS$|.XLSX$|.DOCX$|.PDF$"

Would someone would be able to help. where i am wrong.

---------- Post updated at 11:36 AM ---------- Previous update was at 11:25 AM ----------

Quote:
Originally Posted by codecaine21
Code:
sudo find . -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} dest_dir \;

or

Code:
cp `find . | egrep "*\.(txt|pdf|xls)"` dest_dir

Find in conjunction with the period(.) will start looking from the current directory and prune the rest of the dirs. Meaning it will look in the cwd you are in. Then when it finds a folder it will look in that folder as well.

Find in conjunction with the forward slash(/) will start looking from the top of your directory tree.

Actually I want to transfer from only one single dir. neither the top directory nor any prune required. Thanks for your reply.

looking forward for your reply.
# 7  
Old 03-26-2015
Quote:
Originally Posted by yadavricky
Actually I wanted to put all Extension in a Variable and then search it.

Code:
like ACC_EXT=".TXT$|.DOC$|.XLS$|.XLSX$|.DOCX$|.PDF$"

Would someone would be able to help. where i am wrong.

---------- Post updated at 11:36 AM ---------- Previous update was at 11:25 AM ----------




Actually I want to transfer from only one single dir. neither the top directory nor any prune required. Thanks for your reply.

looking forward for your reply.
Then do
Code:
sudo find dir_to_copy_from -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} dir_to_copy_to \;

Example:
Code:
sudo find /home/codecaine21/Documents/ -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} /home/codecaine21/Documents/Files/ \;

or

Code:
cp `find dir_to_copy_from  | egrep "*\.(txt|pdf|xls)"` dir_to_copy_to

Example:
Code:
cp `find /home/codecaine21/Documents/  | egrep "*\.(txt|pdf|xls)"` /home/codecaine21/Documents/Files/

You should read up on Bash programming. Your understanding of the fundamentals is a bit skewed.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Copy files based on specific word in a file name & its extension and putting it in required location prajaktaraut Shell Programming and Scripting 13 10-24-2016 08:43 AM
Use find with cp and sed in ksh to copy files to a slightly different location ejianu Shell Programming and Scripting 12 10-20-2016 05:47 PM
Copy file from UNIX to shared location Amit786 Shell Programming and Scripting 1 05-29-2014 11:23 AM
How to find a word and move it a specific location in xml file using perl? harpal singh Shell Programming and Scripting 3 03-07-2013 02:57 PM
How to find a existing file location and directory location in Solaris box? buzzme Shell Programming and Scripting 1 01-10-2013 09:13 PM
how to copy files and record original file location? willie8605 UNIX for Dummies Questions & Answers 4 04-16-2012 03:49 PM
How to copy a file from one location to another location? vel4ever Shell Programming and Scripting 1 01-12-2012 05:29 AM
How to copy specific file.txt in specific folder? annetote Shell Programming and Scripting 17 06-02-2010 01:50 PM
Find and replace a string a specific value in specific location in AIX techmoris Shell Programming and Scripting 5 03-11-2010 07:24 PM
Shell Script for Copy files from one location to another location allways4u21 Shell Programming and Scripting 2 01-21-2010 04:26 PM
find pid of process run in specific location JCR Shell Programming and Scripting 4 07-29-2009 05:25 AM
tail copy of a file to remote location unori Shell Programming and Scripting 7 05-21-2009 05:13 PM
Bash copy file contents into an existing file at a specific location gshepherd7 Shell Programming and Scripting 6 03-11-2009 10:26 AM
copy files from one location to similar location pharos467 UNIX for Advanced & Expert Users 1 09-21-2008 01:21 PM
excutable script to copy a file to a different location. nazehcalil UNIX for Dummies Questions & Answers 4 12-21-2006 09:17 AM