2019-03-18

linux find files older than 365 days exclude multiple paths


Navigate to target folder, search sub folders and sort files details older than 365 days with folder exclusion config below:

find . -type d \( -path "./Programs/jdk1.7.xxx" -o -path "./Programs/apache-tomcat-7.0.xxx" -o -path "./Programs/mysql-xxx" \) -prune -o -mtime +365 | sort

Similar as above, but ls -lrth

find . -type d \( -path "./Programs/jdk1.7.xxx" -o -path "./Programs/apache-tomcat-7.0.xxx" -o -path "./Programs/mysql-xxx" \) -prune -o -mtime +365 -exec ls -lrth {} \;




Google'ed: linux find exclude directory






Reference URL: https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command






Use the prune switch, for example if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command:
find . -path ./misc -prune -o -name '*.txt' -print
Here is an example with multiple directories:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
Here we exclude dir1, dir2 and dir3, since in find expressions it is an action, that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d. Further action is -o print, just print.














No comments:

Google Referrals