linux 日志设置定时清理

摘要:
创建shell脚本命令:root@2290b60f3ac6:~#catclearlog。shfind/var/lib/postgresql/data/log/-mtime+10 name“*”-exerm rf{};此命令是find的基本用法。它可以分为两部分:find~/-name“*.aic”和-exerm-rf{};~/:在根目录中查找-name通过“*.aic”文件名查找文件名

创建shell 脚本命令:

root@2290b60f3ac6:~# cat clearlog.sh 
find /var/lib/postgresql/data/log/ -mtime +10 -name "*" -exec rm -rf {} ; 
这个命令是find的基本用法,可以分两部分,find ~/ -name "*.aic"和 -exec rm -rf {} ;
 ~/:在根目录下查找
 -name 查找文件名的方式
 "*.aic"文件名中要求后缀是aic的所有文件
-exec 找到后执行命令
rm -rf {}命令就是删除文件
;这是格式要求的,没有具体含义。

创建定时执行计划:

  • 定时任务编辑命令: crontab -e
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

# 文件中加入该行,表示每天0点执行命令 `sh /root/clearlog.sh`
* 0 * * * sh /root/clearlog.sh

重启cron 服务:

/sbin/service crond start //启动服务 
/sbin/service crond stop //关闭服务 
/sbin/service crond restart //重启服务 
/sbin/service crond reload //重新载入配置 

免责声明:文章转载自《linux 日志设置定时清理》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Webpack 解析css和less【转】JS跨域(ajax跨域、iframe跨域)解决方法及原理详解(jsonp)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Redis学习-安装(一)

实践是检验真理的唯一标准      学习新事物,新技能,动手尝试才是最好的办法,否则就是纸上谈兵,在学习Redis之前,首先要安装redis的运行环境,了解它的基础命令和基本知识。 一.下载redis   进入redis官网的下载页面https://redis.io/download   从这个页面我们可以得到的一些基本信息是,redis分为稳定版和非稳...

(转)Linux网络接口配置文件ifcfg-eth0解析

原文:http://blog.51cto.com/xtbao/1671739 https://www.cnblogs.com/arvintang/p/5990599.html http://blog.csdn.net/jmyue/article/details/17288467 在一个计算机系统中,可以有多个网络接口,分别对应多个网络接口配置文件,在/et...

[转载]Linux C编程-实现文件夹的递归拷贝

copy(读取的路径或名字,目标文件的路径或名字) {        if(读取的是一个文件夹)        {     创造一个文件夹              打开文件夹,读取文件夹的内容              判断是否是一个文件夹  是:递归copy(xx,xx);               否,说明是个文件,拷贝文件            ...

linux kernel的cmdline參数解析原理分析

利用工作之便,今天研究了kernel下cmdline參数解析过程。记录在此。与大家共享。转载请注明出处。谢谢。 Kernel 版本:3.4.55 Kernel启动时会解析cmdline,然后依据这些參数如console root来进行配置执行。 Cmdline是由bootloader传给kernel。如uboot。将须要传给kernel的參数做成一个...

Linux Shell中的延时函数

Linux Shell中的延时函数 在 linux shell 脚本中经常需要做一些延时处理。 所以经常要用到 sleep 或 usleep 函数。 下面来说一下 sleep 和 usleep 的区别: sleep : 默认以秒为单位。 usleep : 默认以微秒为单位。 1s = 1000ms = 1000000us sleep 不但可以用秒为单位,...

在linux中使用ramdisk文件系统 天高地厚

一 什么是RamDisk Ram:内存,Disk:磁盘,在Linux中可以将一部分内存当作分区来使用,称之为RamDisk。对于一些经常被访问、并且不会被更改的文件,可以将它们通过RamDisk放在内存中,能够明显地提高系统性能。RamDisk工作于虚拟文件系统(VFS)层,不能格式化,但可以创建多个RamDisk。虽然现在硬盘价钱越来越便宜,但对于一些...