Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Find and Copy file of specific location


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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  
Please show what you have tried so far.
# 3  
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  
You could try something like:
Code:
find .....  -name "*.txt" -o -name "*.pdf" -o -name "*.xls*" -exec cp .......

# 5  
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  
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  
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
Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR...... Shell Programming and Scripting
13
Shell Programming and Scripting
How to find a word and move it a specific location in xml file using perl?
harpal singh
Hi friends, I have one XML file having below structure :- INput XML file :- <?xml version="1.0" encoding="UTF-8"?> <START> <A=value1> <attr name1="a1"> </A> <B=value2> <attr name2="b1"> <attr name3="c1"> </B> </START> output xml file should be ===... Shell Programming and Scripting
3
Shell Programming and Scripting
How to find a existing file location and directory location in Solaris box?
buzzme
Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box... Shell Programming and Scripting
1
Shell Programming and Scripting
Find and replace a string a specific value in specific location in AIX
techmoris
Hi, I have following samp.txt file in unix. samp.txt 01Roy2D3M000000 02Rad2D3M222222 . . . . 10Mik0A2M343443 Desired Output 01Roy2A3M000000 02Rad2A3M222222 . .... Shell Programming and Scripting
5
Shell Programming and Scripting
Bash copy file contents into an existing file at a specific location
gshepherd7
Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ...... Shell Programming and Scripting
6
Shell Programming and Scripting

Featured Tech Videos