Skip to content
Advertisement

Find and scp in one command

I need to scp all txt files in /home/data directory and its subdirectories.

find /home/data/ -type f -name *.txt -exec scp {} user@ip:/home/testdir ;

The command seemed to work but on the destination server instead of a folder there was a file named testdir and it seemed to have the size of the last txt file that was transfered.

Am I missing something in the command?

Advertisement

Answer

Rsync may be more appropriate for the task. It has very handy include and exclude flags. You can use it like so:

rsync -rav -e ssh --include '*/' --include='*.txt' --exclude='*' 
    server:/usr/folders/  /usr/backup/
Advertisement