How to tar.gz everything under xx MB?
Solution 1:
you can pass the list of files to tar directly (with the T
switch), i.e.:
find dir/ -size -50M | tar -czf test.tgz -T - --exclude '*.gif' --exclude '*.jpg'
Solution 2:
You can combine tar with find to select only the files of a certain size: find . -size -50M
returns a list of all the files under 50 MB, which you can then pipe to tar.
Edit Didn't notice your second question when I first answered: in order to exclude files based on their extension, just pipe the output of find to grep: find ... | fgrep -v \*.jpg \*.png etc.
(untested).
Solution 3:
Extending Arthur's suggestion, tar's r option is for append. So something like this might do it.
find /path/to/dir -size -50M -exec tar -rvpf backup.tar \;
EDIT: -exec needs terminating string "\;" (w/o quotes).
You can't append to a compressed archive, so you will have to gzip it (or bzip2 it) separately.
Combine with wds' solution to exclude images.