I'm looking for a command/script to allow the most recently modified files (up to) 10GB be copied to another computer.So if there are 4 files 4 GB each, only  2 of them should be transferred by the script, If there are 12 files 1GB big, only the most recent 10 should be transferred.
rsync most recent x GB
scripting;rsync;cp;synchronization
Here is a script that does just what you asked for.  The requirementsThe files transferred must total less than a threshold size.The files must be modified compared to the rsync destination.If not all files can be transferred, only the most recently modified files must be selected.The detailsIt uses rsync --dry-run to build a list of files that would be transferred (these are the modified files).  It then uses a combination of du and ls to get file sizes and mtime.  It then sorts the files by mtime and then loops over them until the total size exceeds a threshold.  Finally, it calls rsync again with just the files that are the most recently modified and total size under the threshold.The script is a bit ugly, but it works.  One big limitation is that it must be executed on the machine containing the rsync from-directory.  It can be modified to use ssh to use a remote from-directory, but that excersize is left to the reader.Finally, the rsync options are hard coded into the script, but this is an easy change if you want to specify them on the command line.  Also, the math to calculate size is done in bytes.  This can be changed to kilo/mega/gigabytes by modifying the call to du and reducing the threshold by the same factor.Usage./rsyncrecent.sh rsync-from-directory rsync-to-directorywhere rsync-from-directory is a local directory and rsync-to-directory is any local or remote directory.  The default options are hardcoded as -avz and the default threshold is hardcoded as 10GiB.The script#!/bin/bashRSYNC=rsyncRSYNC_OPTS=-avzTHRESHOLD=10737418240usage () {  echo >&2 Usage:  $0 from-location to-location  exit 1}[ $# -eq 2 ] || usageRSYNC_FROM=$1RSYNC_TO=$2echo Fetching file list for $RSYNC $RSYNC_OPTS $RSYNC_FROM $RSYNC_TO# get list of changed filesFILES=`$RSYNC $RSYNC_OPTS --dry-run  $RSYNC_FROM $RSYNC_TO | sed -n '/list$/,/^$/{/sending.*list$/ d ; /^$/ d ; /\/$/ d ;; p}'`# reported files are relative to ..RSYNC_FROM, so rather than transforming filenames, lets just move therepushd $RSYNC_FROM > /dev/null# get modified time and sizes for all filesi=0for FILE in $FILESdo   #strip first part of path so files are relative to RSYNC_FROM   FILE=${FILE#*/}   #FSIZE=`ls -l $FILE | cut -f5 -d' '`   FSIZE=`du -bs $FILE`   FMTIME=`ls -l --time-style=+%s $FILE | cut -f6 -d' '`   FLIST[$i]=`echo $FMTIME $FILE $FSIZE`   ((i=$i+1))done# go back to original directorypopd > /dev/null# sort list according to modified timeIFS=$'\n' FLIST=($(sort -rg <<<${FLIST[*]}))max=$ii=0size=0#NEWFLIST=''# add up the files in mtime order until threshold is reachedfor ((i=0; i<$max; i++))do   s=`echo ${FLIST[$i]} | cut -f3 -d' '`   f=`echo ${FLIST[$i]} | cut -f2 -d' '`   ((size=$size+$s))   if (( $size > $THRESHOLD ))   then      break   fi   NEWFLIST=$NEWFLIST $f   echo $f >> /tmp/rsyncfilelistdone$RSYNC $RSYNC_OPTS --dry-run $RSYNC_FROM --files-from=/tmp/rsyncfilelist  $RSYNC_TOrm /tmp/rsyncfilelist