Get the App
SLTechnology News&Howtos  ›  Servers  › 

The find command under AIX does not delete directories recursively.

Shulou Source: shulou.com Published: 2022-06-02 12:17:25 09月21日 Update

Scene description:

As shown in the following figure: there is a date command directory under the log directory, and there are directories and Log log files in the directory. Because of the space alarm, the previous data needs to be deleted.

Solution:

Of course, we can use the rm command to delete one by one, to test the convenience of operation and maintenance, we write a script to achieve the best. If it is the linux platform, it is actually very simple:

Find ~ / log-maxdepth 1-mindepth 1-type d-mtime + 149 | xargs rm-rf

Just use the above command. But the find command on the AIX platform is less friendly because it has no maxdepth or mindepth parameters. After looking for a few laps, I found that it could be solved with the following command:

# Delete the date directory under the ~ / log/ directory and retain the 365day data find ~ / log/*-prune-type d-name "20*"-mtime + 365-print | xargs rm-rf # # the above command is also equivalent to: find ~ / log/!-name "."-prune-type-d-name "20*"-mtime + 365-print | xargs rm-rf

The key instructions are:

1. The parameter prune, which means that when a directory is encountered, no recursive lookup is performed.

2. Restrictions on the starting directory, ". / *" and ". /" and ". /-name". "" And ". /. These directories are different. ". / *" starts with all the directories and files in the current directory; while ". /" starts from the current directory; ". /-name". "" Except for all the contents thought by the. / directory, it is equivalent to ". / *";. /. " Or the current directory.

Finally, put the above statement into crontab and you can delete the number every day with a scheduled task.

Reference:

1. Question and answer "Equivalent maxdepth for find in AIX" on stackovernet

2. "thinking caused by find Command-prune parameters" written by My Panda Eye.

Tags: Directory command parameter facet platform data file log date recursion under task key content meaning scenario method is in best space Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS Shulou Technology Linux MySQL