I'm a novice linux user and I am trying to send a long list of files from one computer to another. The argument list is too long, so I am using find. I am having trouble setting up the expression, though. Can someone help?

Here is what I would normally type for a short argument list.

scp ./* phogan@computer/directory...

Here's I think this might translate into with find.

scp find . -name "*" phogan@computer/directory...

Maybe I could use piping? Any suggestions would help. Thanks in advance.

link|improve this question
feedback

4 Answers

up vote 4 down vote accepted
find . -name "*" -exec scp '{}' phogan@computer/directory ';'

normally i would 'tar' all the files together into one huge blob and call 'scp' just once. something like this:

tar czfv - file1 file2 dir1 dir2 | ssh phogan@computer/ tar xvzf - -C directory

one could play around with the --exclude= or --include= parameters of tar. another option would be to use rsync.

link|improve this answer
if using passwords with ssh/scp, wouldn't the solution with find ask for a password on every file? – quack quixote Oct 5 '09 at 21:47
lets just assume he knows how to use ssh-keys :) the problem with 1000 password questions is also the reason for the tar-approach – akira Oct 5 '09 at 23:17
feedback
for f in `find . -name "*"`;do scp $f phogan@computer/directory;done
link|improve this answer
yea he wants a single command anyway – John T Oct 5 '09 at 18:42
useful, used it with grep -l pattern * – Tanj Oct 16 '09 at 17:39
feedback

tar is probably the best way to do this, but you might be able to do this (untested) and avoid multiple password prompts that piping might cause, but it won't handle filenames that include spaces or newlines:

scp $(find . -name "*") phogan@computer:/directory...

Note the added colon that was missing from the command in your question.

link|improve this answer
like this, easier to remember then a for loop I think – Tanj Oct 16 '09 at 17:42
feedback

I would suggest

find . -print0 | tar --null --files-from=/dev/stdin -cf - | ssh phogan@computer tar -xf - -C /directory

Note, that this solution avoids having the filenames on the command line where they might be interpreted as command line arguments.

Another thing to watch out for is that filenames might contain spaces. This means that a for loop in bash might have difficulties with a list of filenames.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.