Deleting three oldest files if 7 days have passed since the oldest
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What I want to do is that if gets all the files and sees the date of the oldest. If the oldest is more tan 7 days, it should get the 3 oldest files and delete them.
please follow the rules of the forum.
show us what did you try, what's happened, what is your actual problem. Do not expect anyone will write something for you.
Especially you missed point 3, 4, and 5.
please follow the rules of the forum.
show us what did you try, what's happened, what is your actual problem. Do not expect anyone will write something for you.
Especially you missed point 3, 4, and 5.
This is the newbie section.
As such, it is supposed that I do not have a clue what I am doing.
So, the question is still the same: How do I check in the directory "/home/theuser/thebackup" the date of files and if the oldest file has more than 7 days, it should delete the 3 oldest files.? Thats my problem
You will need to use the find utility and also sort and awk or head. However, do you really want to delete the three oldest even if two of them are less than seven days old? Or do you want to delete the three oldest files that are all over seven days old?
To get started with find, see -daystart and -mtime and -printf
What I want to do is that if gets all the files and sees the date of the oldest. If the oldest is more tan 7 days, it should get the 3 oldest files and delete them.
The find command can find files of a specified age. I feel you have shown a great deal of code non-related to your question. Perhaps consider not showing the extensive code and instead just the portions where you are trying to located files of a certain age.
Is this code which you've written? What experience do you have with bash scripting? Reason I'm asking is that people will benefit by knowing whether or not you have any experience with scripting at all, or if you are trying to modify a script to accomplish these actions, but do not necessarily have great experience with bash or scripting yourself.
Suggest you put a "set -xv" line in your script to help you debug it.
What I want to do is that if gets all the files and sees the date of the oldest. If the oldest is more tan 7 days, it should get the 3 oldest files and delete them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.