Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to delete files regularly in linux

Shulou Source: shulou.com Published: 2022-06-01 17:02:21 11月10日 Update

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.

Tags: Files scripts questions success more directories help answers easy easy tasks task systems content parameters commands multiple boys buddies hours manual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft macOS Shulou Technology Apple