Delete old log files in AIX

扶醉桌前 提交于 2019-12-08 06:45:18

问题


I am trying write a script to delete old log files in path \var\log\applog\nmon in my AIX system. We usually get this alerts that the file system is almost full and all we do is go to the path and delete old log files. So basically what i am looking for is the script that i can schedule in corn job . This script should keep logs for two months and delete the rest .

Again there are these two files i don't want it to be deleted .

Named:.profile and .sh_history

I tried this command :

find ./My_Dir -mtime  +60 -type f –delete

It works fine but it also deletes those two file which i mentioned earlier .

I am not sure how to proceed with the script so that i can delete old logs file but not those two files.

Thanks


回答1:


You can use the -not -name ... parameter:

find ./My_Dir \
    -mtime  +60 \
    -type f \
    -not -name ".profile" \
    -not -name ".sh_history" –delete

By the way, to delete old files it is always better to use the magnificient logrotate tool.


Update from your comment:

find: 0652-017 -not is not a valid option.

Then use this: ! -name "name_of_file"

find ./My_Dir \
    -mtime  +60 \
    -type f \
    ! -name ".profile" \
    ! -name ".sh_history" –delete


来源:https://stackoverflow.com/questions/16833343/delete-old-log-files-in-aix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!