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

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

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest