Delete old log files in AIX

2019-06-02 21:10发布

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条回答
放荡不羁爱自由
2楼-- · 2019-06-02 22:05

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
查看更多
登录 后发表回答