Louis I. answered 08/15/20
Computer Science Instructor/Tutor: Real World and Academia Experienced
I like your thought process, but I wouldn't over-think this ... you're very close
to a real solution!
In the spirit of "separation of concerns", yes, I like your idea of generating a
file containing the list files to be archived by tar.
But let's not even get that specific yet. Let's just say you want to
commit to NOT burdening tar (the archiver) with determining what needs to be archived.
How would you implement the logic that generates a list of files
under a given directory that meet your archiving criteria?
Why not use the obvious-choice commands like find, grep, etc.?
As an example, if your backup requirements were limited to:
- all C language source files that are less than 4MB
- all Python source files that are less than 4MB
the following one-line script would work:
find $PWD -type f -size -4M -iname "*.py" -o -iname *.c > /tmp/tar/ToBeArchived.txt
Now that we have a list, we can use tar to draw from that list as follows:
tar cvf /tmp/tar/archive.tar -T /tmp/tar/ToBeArchived.txt
BTW, we generally could do something like this in one step using command substitution ...
tar cvf /tmp/tar/archive.tar $(scriptThatGeneratesList)
but if the list of files is substantial, the buffer size limit
allocated for command line parameters might get exhausted.
Using tar's "-T file" option is the safer bet ...