Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 11 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
Which scp version, which linux distribution it that? E.g. scp in Ubuntu 14.04 does not have this option. – geekQ Aug 19 '15 at 9:47
Hi, older versions support it, the new versions support a simpler command: scp `find <path> -name <expression>` user@host:<path_where_to_copy> – Carlos Rodrigues Aug 28 '15 at 16:48
Doesn't work on multiple files – Amruta Jul 8 at 20:33
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .