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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
You don't have to use it for the /var/log tree you can customize your profile to look at other files and delete those after they reach a certain size or age. Takes a bit of fooling with, but I used it to rotate and deprecate logs from an application I wrote so as to not overflow disk size but also keep the logs and offload them once they were swapped out.
The find command is very good at finding files and directories of a specified age. I would try to use it as the basis for keeping track of files matching various age thresholds. Keeping track of file and directory age information is redundant, since the filesystem already does this, and is automatically up-to-date.
If you use '-ctime -20' in the argument to find, you will find files that are less than 20 days old (creation time; do you really mean modification time?). From your original post, it sounded like you wanted to find files that are older than a certain age. To do that, you would want to change the leading minus sign in the numeric argument to a plus sign.
Also, the use of cut to trim the leading directory name from files relies on the case that the files found are exactly 4 levels deep from the root. Better would be to use the built-in basename function. Example:
In your original post, you said you were looking for directories beyond 3 months old. To find directories with find, you would use the -type d option. I think it makes more sense to deal with files & directories, and this seems to be what you have adopted.
My example showed how to send the list of files to a user by e-mail:
echo $oldFiles | mail -s "Deleting files from /some/start/directory" ADMIN@your.site