How to copy a file from one location to another location?

I have file file1.txt in location 'loc1'. Now i want a copy of this file in location 'loc2' with a new file called test.txt.

Please help me how to do this in shell script.

If loc2 is same server then use cp, else if its different server then use scp command

cp ${loc1}/file1.txt ${loc2}/test.txt 
 
(or)
 
scp hostname:${loc1}/file1.txt hostname:${loc2}/test.txt
1 Like