Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 8 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.

share|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

You can do it with just one command SCP:

scp --exec=`find <path> -name <expression>` user@host:<path_where_to_copy>
share|improve this answer
for f in `find . -name "*"`;do scp $f phogan@computer/directory;done
share|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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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