21

Is there a way to copy local files with curl, I need it to work as an alternative for cp command.

This is a bit strange, but I'm working on an environment where cp is not available.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
zibi
  • 3,183
  • 3
  • 27
  • 47
  • 4
    Pretty sure you don't care at all 2 years after, but I would have avoided `curl` and used `cat` + basic shell redirection : `cat sourceFile > targetFile` – Aaron Nov 09 '16 at 16:04

2 Answers2

32

You could say:

curl -o /path/to/destination file:///path/to/source/file 

This would copy /path/to/source/file to /path/to/destination.

Community
  • 1
  • 1
devnull
  • 118,548
  • 33
  • 236
  • 227
  • 1
    or ```curl file:///path/to/source/file > /path/to/destination``` which uses plain shell redirection. – Carlos Apr 27 '17 at 13:47
1

you can use rsync

rsync -avz /path/to/src/file /path/to/dst/dir

You can also use tar

cd /path/to/src/dir; tar -cpf - sourcefile | (cd /path/to/dest/dir; tar -xpf -)

if your tar support -C

cd /path/to/src/dir; tar -cpf - sourcefile | tar -xpf - -C /path/to/dest/dir
ray
  • 4,109
  • 1
  • 17
  • 12