Originally Posted by cylon
I'm still not clear. I understand that this finds the file and attempts to execute something.
What I don't understand is how to output the actual files that "find" discovers and output them into the existing tar file. Once the files are in the tar file, the source files should be deleted.
This should work:
find $path -type f -user cylon -mtime +5 | while read filepath
echo "Processing $filepath."
echo "Adding $filepath to tar archive..."
if tar archive-name --append $filepath
echo "Successfully added $filepath to archive."
echo "Deleting $filepath..."
if rm -f $filepath
echo "Successfully deleted $filepath"
echo "Error: could not delete $filepath"
echo "Error: could not add $filepath to archive."
But bear in mind these warnings
1. The file filtering code finds all files older than five days, but it doesn't distinguish between ordinary data files and system files that might reside in the user's directory (and that shouldn't be deleted). A more sophisticated filtering method would be required to filter only normal data files, not system files (like Gnome and KDE configuration files, for example).
2. I haven't actually created an archive and appended files to it, to see what happens. So you need to actually test this method carefully on copies
of example files, not the originals. My untested tar syntax might be wrong
-- tar is a rather complex bit of code. Maintain full backups during testing.