In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to delete files regularly in linux? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
[oracle@TEST arch] $cat d-archivelog.sh
#! / bin/bash
Find / arch/-mtime + 2-name'* .dbf'- exec rm-rf {}\
Find directory-mtime + date-name file name-exec-rm-rf {}\
Delete the files in * .dbf format 2 days ago in the / arch/ directory
Create the documentation for the experiment
-t STAMP
Use [[CC] YY] MMDDhhmm [.ss] instead of current time
[oracle@TEST arch] $touch-t 201701080101 a.dbf
[oracle@TEST arch] $touch-t 201701070101 b.dbf
[oracle@TEST arch] $touch-t 201701060101 c.dbf
[oracle@TEST arch] $touch-t 201701050101 d.dbf
Add execution permissions to shell scripts
[oracle@TEST arch] $chmod + x d-archivelog.sh
[oracle@TEST arch] $ll
Total 4
-rw-r--r-- 1 oracle oinstall 0 Jan 8 01:01 a.dbf
-rw-r--r-- 1 oracle oinstall 0 Jan 7 01:01 b.dbf
-rw-r--r-- 1 oracle oinstall 0 Jan 6 01:01 c.dbf
-rwxr-xr-x 1 oracle oinstall 65 Jan 9 18:34 d-archivelog.sh
-rw-r--r-- 1 oracle oinstall 0 Jan 5 01:01 d.dbf
Execute the script with an error reported, but can be executed successfully in command line mode
[oracle@TEST arch] $. / d-archivelog.sh
Find: paths must precede expression
Usage: find [- H] [- L] [- P] [path...] [expression]
[oracle@TEST arch] $find / arch/-mtime + 1-name * .dbf-exec rm-rf {}\
[oracle@TEST arch] $ls
Darchivelog.sh
Found to be the find-name parameter * .dbf is multiple files should be added to the script'* .dbf'
In this way, the execution was successful.
[oracle@TEST arch] $cat d-archivelog.sh
#! / bin/bash
Find / arch/-mtime + 2-name'* .dbf'- exec rm-rf {}\
[oracle@TEST arch] $. / d-archivelog.sh
[oracle@TEST arch] $ll
Total 4
-rw-r--r-- 1 oracle oinstall 0 Jan 8 01:01 a.dbf
-rw-r--r-- 1 oracle oinstall 0 Jan 7 01:01 b.dbf
-rwxr-xr-x 1 oracle oinstall 67 Jan 9 18:43 d-archivelog.sh
Add to scheduled task
The system automatically assigns files
[oracle@TEST arch] $crontab-e
[oracle@TEST arch] $crontab-l
* 1 * / arch/d-archivelog.sh
Time-sharing, day, moon and week
Specify the file manually
[oracle@TEST arch] $vim log.cron
1 * / arch/d-archivelog.sh
[oracle@TEST arch] $crontab log.cron
[oracle@TEST arch] $crontab-l
1 * / arch/d-archivelog.sh
Execute the script at the first minute of every hour
This is the answer to the question about how to delete files regularly in linux. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.