Linux - find - How to exclude a directory

Inside the /tmp I want to find files older than 180 day, but I also want to exclude some folders from the search like ./vboxdrv-Module.symvers. How can I perform the task with find?

1 Answer

This syntax will do what you want:

find -not -newermt 2016-11-10 -not -path "./"

Change with whatever settings you want.

Add as many -not -path you want after each other. Ie.

find -not -newermt 2016-11-10 -not -path "./folder1/*" -not -path "./folder2/*"

Or if you want to do it from another folder:

find /tmp/ -not -newermt 2016-11-10 -not -path "/tmp/folder1/*" -not -path "/tmp/folder2/*"
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like