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
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
Please show what you have tried so far.
I tried below 2 things
ALL_ACC_EXTNS=(dat, txt, pdf)
for i in "${ALL_ACC_EXTNS[@]}"; do
cp ${Source}/*.$i $Destination
done
and second try with
ACC_EXT=".TXT$|.PDF$|.XLSX$"
find . -name $(echo $AACC_EXT) -type f -exec cp -t '$Destination' {} +
Both didn't work for me.
You could try something like:
find ..... -name "*.txt" -o -name "*.pdf" -o -name "*.xls*" -exec cp .......
sudo find . -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} dest_dir \;
or
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 wanted to put all Extension in a Variable and then search it.
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
sudo find dir_to_copy_from -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} dir_to_copy_to \;
Example:
sudo find /home/codecaine21/Documents/ -regextype posix-extended -regex ".*\.(txt|xls|pdf)" -exec cp {} /home/codecaine21/Documents/Files/ \;
or
cp `find dir_to_copy_from | egrep "*\.(txt|pdf|xls)"` dir_to_copy_to
Example:
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.