Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy entire content from a folder to another in shell script

I'm trying every single code to copy all things inside a folder to another but i can't do it! I'm trying to use the code in my terminal emulator in my android device because i need that code in my application. This is the last code i use that doesn't work:

#!/bash/sh
srcdir="/data/app"
dstdir="/sdcard/prova1"

for f in ${srcdir}/*.apk
do
    cp $f $dstdir $dstfile
done

and the terminal says:

: not found
' unespectedsyntax error: 'do

can anyone help me? These are the possibility that could be good:

1) Copy all files in the /data/app folder to /sdcard/prova1

2) Copy directly the folder app in prova1

3) Use a java code that do one of these two things..

I have root so i can do this operation.

like image 822
David_D Avatar asked Nov 26 '13 20:11

David_D


2 Answers

None of these answers worked for me for recursive copy. Found this in a script in one of my libraries and thought I'd share it (with a subfolder example for both the source and destination, which is what I needed):

SOURCE="/my/folder"
DESTINATION="/my/destination"

cp -r "$SOURCE/subdir/"* "$DESTINATION/another_sub/"

With this, every subfolder and every file was copied.

I don't know why but the asterisk outside the quotes in the source did the magic for me (using bash 4.3.11 here)

like image 130
Lucio Mollinedo Avatar answered Sep 18 '22 01:09

Lucio Mollinedo


how about this, where src and dest are directories: cp -r src dest

like image 33
Michael Ford Avatar answered Sep 20 '22 01:09

Michael Ford