Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
We have monthly backups and yearly backups, and wanted to keep files for the 12 months and delete the older months. Is it similar to delete files older than x days for ex:
I would definitely advise running it without the action to make sure it's affecting the correct files
Code:
find /your/dir/ -type f -mtime +365
Code:
-delete
Delete files; true if removal succeeded. If the removal failed,
an error message is issued. If -delete fails, find's exit sta‐
tus will be nonzero (when it eventually exits). Use of -delete
automatically turns on the `-depth' option.
Warnings: Don't forget that the find command line is evaluated
as an expression, so putting -delete first will make find try to
delete everything below the starting points you specified. When
testing a find command line that you later intend to use with
-delete, you should explicitly specify -depth in order to avoid
later surprises. Because -delete implies -depth, you cannot
usefully use -prune and -delete together.
Together with the -ignore_readdir_race option, find will ignore
errors of the -delete action in the case the file has disap‐
peared since the parent directory was read: it will not output
an error diagnostic, and the return code of the -delete action
will be true.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818
Rep:
Quote:
Originally Posted by 1s440
Hi all,
We have monthly backups and yearly backups, and wanted to keep files for the 12 months and delete the older months. Is it similar to delete files older than x days for ex:
Code:
find /your/file -mtime +365 -exec rm {} +
logrotate(8) would help keep the older log files under control without you having to manually find/delete them. It's not limited to the files under /var/log and non-root users may institute their own logrotate function via cron. Recommendation: use the "-d/-v" (debug and verbose) switches when testing it to show you what's liable to be deleted without actually deleting the files. Remove the "-d" switch when you're satisfied it's configured to do what you require.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.