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.


1 Answer 1


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/ \;
  • 1
    A note for the OP: rsync is similar to scp, but more efficient, as it transfers only changes if a file is modified. Jul 19, 2017 at 12:46
  • 1
    be careful with the order of directories as rsync -rv --max-size SOURCE DESTINATION. I didn't read properly, and this coud have very bad consequences.
    – toto_tico
    Jan 28, 2019 at 11:50

This site is temporarily in read-only mode and not accepting new answers.

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