Ubuntu – How to scp files of size less than x

command linescp

I am developing something on my laptop and scp'ing the files to a high performance PC (a server with no monitor). Out of laziness I just do this currently (on the laptop):

scp -r ~/project/* server:~/project/

However some of the files in the project directory are some log files and out files which I don't need to send, which can sometimes be a gig or so. What I would like is a nice clean command which basically does the same thing (transmits all the files in project and its subdirectories) but only sends files under a certain filesize threshold, such as 100 mb. I'm only mildly experienced with bash and not at all with regexp so I don't really have any idea how to do this without some convoluted method such as importing sys into python and using a bunch of ifs and comparisons.

Best Answer

you can use 'rsync' command which has an option to controlling the file size to be excluding.

rsync -rv --max-size=100m /path/in/local/ server:~/project/

from 'man rsync',

--max-size=SIZE    don't transfer any file larger than SIZE

Updated answer : simply exclude the log files with 'rsync' --exclude option as below

rsync -rv --exclude='*.log' --max-size=100m /path/in/local/ server:~/project/

or you can use the 'find' command combination with 'scp' and specify the file size limit with its -size option. use ! -name '*.log' to exclude the certain files end with 'log'.

find /path/in/local -type f ! -name '*.log' -size -100m -exec scp '{}' server:~/project/ \;