Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude big files while compressing a directory with tar

I want to compress a directory in Linux. I created a tar.gz that it turns to be a big file, due to the reason that the directory contains some *.o files and some pdf files.

Is there any way to compress a directory but exclude files larger than a predefined SIZE? There is a --exclude argument in tar command, however I would like to reject files larger than 1 MB. This is the constrain, not the name of the file.

like image 848
cateof Avatar asked Nov 14 '22 09:11

cateof


1 Answers

Based on Jan-Philip Gehrcke's response:

find . -type f -size -1024k -print0 | tar -czf --null -T - -f archive.tar.gz

for files less than 1M. Tested on OS X and Ubuntu Linux.

like image 121
fredbaba Avatar answered Dec 06 '22 14:12

fredbaba