ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hello, I need some help from you guys ;] Can someone help me write a bash scrip? Basically I need to write a script, where you input a date and the script shows files older then the inputed date. Can someone help me with this ? :]
Could you be more courteous to the people around. We guys are here to help not to spoonfeed. If you are not willing to devote your time to figure out how you can learn then it will not going to work.
Anyways back to your query. As I can understand you want to find out the files which are older than X days.
Here are some tips:
1. find command is capable of finding the files older than X days. Following is the syntax: find / -type f -mtime +X . Where X will be the number of days.
2. You can use read command in your script to get the user input.
3. Basically what you are looking for is to find the difference between the date entered and today's date and then use as an input for -mtime +X
4. Remember you have to keep a track of date, month and year as well. What I mean to say that year changes after every 365 or 366 days so keep that in consideration.
Now, it is upto you how you can figure out how you could do that. Try to create a script and get back to us if you have any query.
Hint: You can get the today's date in variable using the following: TODAY=$(date '%Y%m%d')"
Last edited by T3RM1NVT0R; 10-15-2011 at 07:17 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.