I want to archive files (with tar) which are below 3 MB in size. But I also want to retain the directories in which those files exist. (so I cannot use find command). I just want to avoid the files which are above 3 MB in size. How can this be done?

link|improve this question

69% accept rate
So why can't you use find again? – Ignacio Vazquez-Abrams Feb 8 '11 at 6:28
Can the find command keep the directories intact? – nixnotwin Feb 8 '11 at 6:48
feedback

1 Answer

up vote 4 down vote accepted

Simpler than you think:

$ tar cf small-archive.tar /big/tree --exclude-from <(find /big/tree -size +3M)

On a semi-related note (relating to your statement that you can't use find) to get a listing of all files (including directories) under a path minus files larger than 3MiB, use:

$ find . -size -3M -o -type d

You could then do:

$ tar cf small-archive.tar --no-recursion --files-from <(find /big/tree -size -3M -o -type d)

But I'd prefer the first one as it's simpler, clearly expresses what you want and will lead to less surprises.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.