Copy entire content from a folder to another in shell script Copy entire content from a folder to another in shell script shell shell

Copy entire content from a folder to another in shell script


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)


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


Your file contains carriage returns, which is why you're getting these trashed error messages. Use tr -d '\r' <yourscript >fixedscript to get rid of them.

As for your script, the correct way to do it is

#!/bin/shcp /data/app/*.apk /sdcard/prova1

While the smallest fix to make your version work is

#!/bin/shsrcdir="/data/app"dstdir="/sdcard/prova1"for f in ${srcdir}/*.apkdo    cp $f $dstdirdone