In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how Linux automatically cleans up the directory files N days ago". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Linux automatically cleans up directory files N days ago.
The server produces global backup files once a week, with a size of about 100g, which needs to be cleaned regularly.
When the visit to the website is large during working hours, deleting big data when the server Iamp O is high will have a bad impact on the status of the server. So I want to use the scheduled task to execute automatically.
Under my backup directory / bakcup, each backup file is named the directory name as a date:
# ls 2013-12-23 2014-01-06 2014-01-20 2014-02-03 2013-12-30 2014-01-13 2014-01-27 2014-02-10
Delete part of the backup while keeping part, you can use the find command, such as I want to keep the files backed up in the last four weeks, each backup interval of seven days:
# find / bakcup/-maxdepth 1-type d-mtime + 28 / bakcup/2014-01-06 / bakcup/2014-01-13 / bakcup/2013-12-23 / bakcup/2013-12-30
-maxdepth 1: set the search directory depth to 1 and search only under the / backup directory. If this parameter is not added, all the files in the subordinate directory will be listed.
-type d: set the lookup type to directory
-mtime + 28: find directories from 28 days ago
After the search, you can use the-exec parameter to connect and delete the command.
Rsync-delete-before-d / data/test/ {}\
Rm is not used here because rsync has an advantage over rm in deleting a large number of files. For specific reasons, please refer to "Why can rsync delete 400000 files quickly?" ".
So, the whole order is:
# find / bakcup/-maxdepth 1-type d-mtime + 28-exec rsync-- delete-before-d / data/test/ {}\
* you can put the command into the script and set crontab to execute automatically.
Reminder:
Before using the command, you should try the find part of the command on the server, and if you find only the directory you want to clean up, you can continue.
Do not rule out the possibility that some systems will look up the. / directory. Be sure to read it carefully to prevent accidents.
In addition, you can replace-exec with-ok, which has the same effect. Remind the user to confirm before deletion.
At this point, I believe you have a deeper understanding of "how to automatically clean up the directory files N days ago by Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.