If a criminal gets into a system or a rouge employee does bad things to data, that is normally not discovered immediately, something it might be not be discovered for many days, weeks or even months.
Three days of backup assumes that you are not concerned about any of those basic IT security topics and you just want to restore from a crash.
That's a very narrow view of the reason for making backups.
You had not said anything about being an admin or about not being an admin in this thread until post #7 in this thread. Please do not assume that everyone has read all of your posts in all of the threads in which you have posted a comment when replying to one of your threads. Assume that each thread is complete on its own without needing to know what has been discussed in other threads unless a link to those other threads has been included. (This includes ALWAYS telling us what operating system and shell you're using when starting a thread in this forum.)
When you ask us how to delete the 3 oldest files in a directory, you're likely to get suggestions that will tell you how to delete the 3 oldest files in a directory (no matter how many files that leaves untouched).
If you ask us how to delete backup files that are more than six months old, you're likely to get suggestions that will tell you how to delete backup files that are more than six months (or more than 180 days) old.
Not mentioning that you're working on backup files (until post #5 in a thread) when there seems to be a hidden requirement to keep a certain number of backups or backups for a certain period of time, makes it unlikely that any early suggestions you get will be of much help.
You have a lot of context that guides you when you're trying to decide what you want to do. If you don't share that context with us when you ask for help, it is unlikely that the help we try to provide will actually help meet your unstated requirements.
Ok, I will try to err on the side of providing too much info even if includes repeating previous info.
------ Post updated at 08:50 AM ------
I modified your script a little. I want to delete all but the newest 2 files.
ls -1t /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Documents_Backups/Ubuntu_Documents_* |
# skip (leave) the 5 newest
tail -n +6 |
# show (delete) the 3 oldest
tail -n -3 |
while IFS= read -r file
do
echo rm "$file"
done
exit 0
This is what is in /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Documents_Backups/ when I ran script and remained the same after running the script.
-rw-rw-r-- 1 andy andy 29454294 Aug 13 07:59 Ubuntu_Documents_2018-08-13-07-59.zip
-rw-rw-r-- 1 andy andy 29454294 Aug 12 18:03 Ubuntu_Documents_2018-08-12-18-03.zip
-rw-rw-r-- 1 andy andy 29454294 Aug 12 15:22 Ubuntu_Documents_2018-08-12-15-22.zip
-rw-rw-r-- 1 andy andy 0 Jan 1 2012 Ubuntu_Documents_2018-08-12-15-40.zip