Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
I have a cron job which tars/compresses various files on a daily basis. So that I don't eventually run out of space, what I need to do now is write a shell script to remove files in a specified directory which are older than, say, 60 days. Does anyone have a simple way to do this? Or, can someone point me in the right direction?
Click here to see the post LQ members have rated as the most helpful post in this thread.
This command will do a search in /var/log for all files that were last modified 60 or more days ago and executes a recursive forced (-rf) remove (rm). The "{}" (curly braces) is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement. Find is very powerful, and I suggest you do some reading BEFORE you do any removing using "find". Also, as a test you can replace the "rm -rf" with "ls -la" to get a list of all the files that would be removed. And, if you want to remove files with specific names or extensions use the "-name" argument.
I have a similar issue. I need to schedule a job, but can't figure out the syntax. I want a job to run daily at 12:00 a.m. The job will delete all files in a certain directory that were created prior to 12:00 a.m.
What is the syntax to accomplish this task? I use a Bourne shell.
@WindozBytes: have you looked into logrotate, it does exactly that sort of thing.
Its part of the std install in linux, look in /etc for logrotate.conf, logrotate.d & man logrotate.
I've got the very same script running in a cron job, but since nothing is 'modifying' the log files, they don't get deleted. I've tried using -ctime but having the same results. Is there a switch or some kind of command that will sort (delete) based on raw age of the file?
I have a similar issue. I need to schedule a job, but can't figure out the syntax. I want a job to run daily at 12:00 a.m. The job will delete all files in a certain directory that were created prior to 12:00 a.m.
What is the syntax to accomplish this task? I use a Bourne shell.
Thank you.
Are you asking about the scheduling (see the crontab man page and ask again if that doesn't tell you what you need to know) or about deleting the files? If the script runs at 12 AM and you want to delete all files created before that time then rm /my_directory/* will do the job (unless you have "hidden" files starting with a ".").
I have a similar issue. I need to schedule a job, but can't figure out the syntax. I want a job to run daily at 12:00 a.m. The job will delete all files in a certain directory that were created prior to 12:00 a.m.
What is the syntax to accomplish this task? I use a Bourne shell.
Thank you.
------------
create a crontab file using "crontab -e" & and "crontab -l" to list it.
place the line -
*/59 */11 * * * /script_path arg1 arg2. as required.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.