2

I'm running the following as part of my Travis CI build on macOS to delete all non-.git directories:

$ if [ "${TRAVIS_OS_NAME}" = "osx" ]; then find /usr/local/Homebrew \! -regex ".+\.git.+" -delete; fi

The output it gives is:

find: -delete: /usr/local/Homebrew: relative path potentially not safe

Why is my /usr/local/Homebrew path being considered a relative path?

1 Answer 1

5

From this answer on Unix & Linux SE:

macOS find is based on an older version of FreeBSD find whose -delete would not remove the files that were given as argument.

[…]

That was changed in FreeBSD in 2013, but the change apparently didn't make it to macOS.

Specifically in your case /usr/local/Homebrew is given as argument to find; therefore -delete cannot remove this exact object. The message relative path potentially not safe is misleading though. The linked message sheds some light on what happens under the hood. It also states:

Deleting the pathnames given as arguments can be prevented without error messages using -mindepth 1 or by changing directory and passing . as argument to find.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.