The find command under AIX does not delete directories recursively.
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.