3

I am trying to move very big file from one host to another host. Also the file names are too large so I have to use xargs. Also all the sub directories need to be copied also

I am using the below command in the source host current directory

find . -name "*" -type f -print0 | xargs -0 scp -r UserName@host:/path/to/destination

but it is throwing below error

scp: /path/to/destination: not a regular file
Anirban Nag 'tintinmj'
  • 5,572
  • 6
  • 39
  • 59

1 Answers1

8

you need to use {} to put the src filename before the destination. Here is the new command:

find . -name "*" -type f -print0 | xargs -0 -I {} scp -r {} UserName@host:/path/to/destination
Peter Skarpetis
  • 543
  • 3
  • 11
  • Almost there, but one thing I need that sub-directories should be also copied.. but for now only the contents of the sub directories are being moved. Secondly, the command is asking for password every time it copies one file. Any solution? – Anirban Nag 'tintinmj' Aug 20 '16 at 13:51
  • if you want directories to be copied then remove the -f parameter from the find command. if you do not want to type in passwords all the time then add your public ssh id to the remote machine and use ssh-agent to store your key on the machine you ru. the command from. – Peter Skarpetis Aug 20 '16 at 13:58
  • So I removed `-f` and the files of sub-directories are getting copied twice. One time on the `/path/to/destination` and again `/path/to/destination/source_folder/`. I hope you can understand my problem. – Anirban Nag 'tintinmj' Aug 20 '16 at 14:02
  • Well this seems to be a whole different issue. You should post another question detailing your problem with examples and someone will answer it – Peter Skarpetis Aug 20 '16 at 14:05