Hi, I would modify to delete the files after creating the tar archive.
How I can modify the following command:
tar -cvvf logswitch.tar `find *.log* -mtime +5`
It create a tar with files that are older than 5 days.
Hi, I would modify to delete the files after creating the tar archive.
How I can modify the following command:
tar -cvvf logswitch.tar `find *.log* -mtime +5`
It create a tar with files that are older than 5 days.
Try this:
tar -cvf logswitch.tar `find *.log* -mtime +5` && find *.log* -mtime +5 -exec rm {} \;
Is there the possibility to erase the files using an option of the tar command?
I found the solution:
tar -cvvf logswitch.tar `find *.log* -mtime $Days` --remove-files
Good, but It'll work with GNU tar only
save file list in variable or file.
FILES=$(find ...)
or
find ... > /tmp/$(USER).flist.$$
then you can remove the files after the tar, without running find twice, (which might be a heavy process or) its state may change between the first and second iteration, causing you to actually lose data.
For example: if you run the command close to midnight. the first +5 will find files just older than 5 days and the second running after midnite will add files a day older. and even if you use it in the middle of the day, the timestamp of files can cause a miss the same way.