“relative path potentially not safe” error with “find … -delete” on macOS
I'm trying to delete all files containing a certain text like this:
$ find ~/Library/MobileDevice/Provisioning Profiles/* -exec grep -l "text to search for" '{}' ; -delete
/Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision
find: -delete: /Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision: relative path potentially not safe
However, as you can see, it's throwing a warning and then does not delete the file. How can I resolve this error?
This is on a Mac.
find osx
add a comment |
I'm trying to delete all files containing a certain text like this:
$ find ~/Library/MobileDevice/Provisioning Profiles/* -exec grep -l "text to search for" '{}' ; -delete
/Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision
find: -delete: /Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision: relative path potentially not safe
However, as you can see, it's throwing a warning and then does not delete the file. How can I resolve this error?
This is on a Mac.
find osx
add a comment |
I'm trying to delete all files containing a certain text like this:
$ find ~/Library/MobileDevice/Provisioning Profiles/* -exec grep -l "text to search for" '{}' ; -delete
/Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision
find: -delete: /Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision: relative path potentially not safe
However, as you can see, it's throwing a warning and then does not delete the file. How can I resolve this error?
This is on a Mac.
find osx
I'm trying to delete all files containing a certain text like this:
$ find ~/Library/MobileDevice/Provisioning Profiles/* -exec grep -l "text to search for" '{}' ; -delete
/Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision
find: -delete: /Users/build/Library/MobileDevice/Provisioning Profiles/06060826-3fb2-4d71-82c6-7b9d309b08d6.mobileprovision: relative path potentially not safe
However, as you can see, it's throwing a warning and then does not delete the file. How can I resolve this error?
This is on a Mac.
find osx
find osx
edited yesterday
Rui F Ribeiro
39.8k1479133
39.8k1479133
asked yesterday
Bart van den BurgBart van den Burg
14115
14115
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
macOS find
is based on an older version of FreeBSD find
whose -delete
would not remove the files that were given as argument.
When you do:
find dir/* ... -delete
Your shell is expanding that dir/*
glob into a list of file paths (excluding the hidden ones, while find
itself will not exclude the hidden files it finds in any of those dirs), so find
receives something like:
find dir/dir1 dir/dir2 dir/file1 dir/file2... ... -delete
If dir/file1
matches macOS find
's -delete
will refuse to delete it. It will happily delete a dir/dir1/.somefile
if it matches though.
That was changed in FreeBSD in 2013, but the change apparently didn't make it to macOS. Here, the work around is easy: use find dir
(or find dir/
if you want to allow for dir
to be a symlink to a directory and find
to descend into it) instead of find dir/*
. So, in your case:
find ~/Library/MobileDevice/Provisioning Profiles/
-exec grep -l "text to search for" '{}' ; -delete
Or use the more efficient grep -l --null | xargs -0
approach.
add a comment |
Try:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -name "name to match" -delete
Edit - first code is not abswer for question, try this:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -exec grep -l --null "pattern in file" {} + | xargs -0 rm
New contributor
1
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
You can't usexargs
in general on the output offind
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem withfind | xargs
)
– Stéphane Chazelas
yesterday
1
No, I meant-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOSgrep
should also support GNU's--null
option so-exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).
– Stéphane Chazelas
yesterday
1
Yes. It's correct (there are some race condition issues linked to usingxargs rm
instead of-delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).
– Stéphane Chazelas
yesterday
|
show 4 more comments
This is searching for string err
in all files in /var/log/
recursive.
I'm not sure if cut
, uniq
and xargs
is available on Mac and this is not using find
.
grep -r "err" /var/log/ | cut -d: -f1 | uniq | xargs echo
Replace echo
with rm
to delete the files.
'find',cut
,uniq
andxargs
are standard Unix utilities available on any Unix platform.
– Kusalananda
yesterday
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497666%2frelative-path-potentially-not-safe-error-with-find-delete-on-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
macOS find
is based on an older version of FreeBSD find
whose -delete
would not remove the files that were given as argument.
When you do:
find dir/* ... -delete
Your shell is expanding that dir/*
glob into a list of file paths (excluding the hidden ones, while find
itself will not exclude the hidden files it finds in any of those dirs), so find
receives something like:
find dir/dir1 dir/dir2 dir/file1 dir/file2... ... -delete
If dir/file1
matches macOS find
's -delete
will refuse to delete it. It will happily delete a dir/dir1/.somefile
if it matches though.
That was changed in FreeBSD in 2013, but the change apparently didn't make it to macOS. Here, the work around is easy: use find dir
(or find dir/
if you want to allow for dir
to be a symlink to a directory and find
to descend into it) instead of find dir/*
. So, in your case:
find ~/Library/MobileDevice/Provisioning Profiles/
-exec grep -l "text to search for" '{}' ; -delete
Or use the more efficient grep -l --null | xargs -0
approach.
add a comment |
macOS find
is based on an older version of FreeBSD find
whose -delete
would not remove the files that were given as argument.
When you do:
find dir/* ... -delete
Your shell is expanding that dir/*
glob into a list of file paths (excluding the hidden ones, while find
itself will not exclude the hidden files it finds in any of those dirs), so find
receives something like:
find dir/dir1 dir/dir2 dir/file1 dir/file2... ... -delete
If dir/file1
matches macOS find
's -delete
will refuse to delete it. It will happily delete a dir/dir1/.somefile
if it matches though.
That was changed in FreeBSD in 2013, but the change apparently didn't make it to macOS. Here, the work around is easy: use find dir
(or find dir/
if you want to allow for dir
to be a symlink to a directory and find
to descend into it) instead of find dir/*
. So, in your case:
find ~/Library/MobileDevice/Provisioning Profiles/
-exec grep -l "text to search for" '{}' ; -delete
Or use the more efficient grep -l --null | xargs -0
approach.
add a comment |
macOS find
is based on an older version of FreeBSD find
whose -delete
would not remove the files that were given as argument.
When you do:
find dir/* ... -delete
Your shell is expanding that dir/*
glob into a list of file paths (excluding the hidden ones, while find
itself will not exclude the hidden files it finds in any of those dirs), so find
receives something like:
find dir/dir1 dir/dir2 dir/file1 dir/file2... ... -delete
If dir/file1
matches macOS find
's -delete
will refuse to delete it. It will happily delete a dir/dir1/.somefile
if it matches though.
That was changed in FreeBSD in 2013, but the change apparently didn't make it to macOS. Here, the work around is easy: use find dir
(or find dir/
if you want to allow for dir
to be a symlink to a directory and find
to descend into it) instead of find dir/*
. So, in your case:
find ~/Library/MobileDevice/Provisioning Profiles/
-exec grep -l "text to search for" '{}' ; -delete
Or use the more efficient grep -l --null | xargs -0
approach.
macOS find
is based on an older version of FreeBSD find
whose -delete
would not remove the files that were given as argument.
When you do:
find dir/* ... -delete
Your shell is expanding that dir/*
glob into a list of file paths (excluding the hidden ones, while find
itself will not exclude the hidden files it finds in any of those dirs), so find
receives something like:
find dir/dir1 dir/dir2 dir/file1 dir/file2... ... -delete
If dir/file1
matches macOS find
's -delete
will refuse to delete it. It will happily delete a dir/dir1/.somefile
if it matches though.
That was changed in FreeBSD in 2013, but the change apparently didn't make it to macOS. Here, the work around is easy: use find dir
(or find dir/
if you want to allow for dir
to be a symlink to a directory and find
to descend into it) instead of find dir/*
. So, in your case:
find ~/Library/MobileDevice/Provisioning Profiles/
-exec grep -l "text to search for" '{}' ; -delete
Or use the more efficient grep -l --null | xargs -0
approach.
edited yesterday
answered yesterday
Stéphane ChazelasStéphane Chazelas
303k57570926
303k57570926
add a comment |
add a comment |
Try:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -name "name to match" -delete
Edit - first code is not abswer for question, try this:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -exec grep -l --null "pattern in file" {} + | xargs -0 rm
New contributor
1
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
You can't usexargs
in general on the output offind
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem withfind | xargs
)
– Stéphane Chazelas
yesterday
1
No, I meant-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOSgrep
should also support GNU's--null
option so-exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).
– Stéphane Chazelas
yesterday
1
Yes. It's correct (there are some race condition issues linked to usingxargs rm
instead of-delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).
– Stéphane Chazelas
yesterday
|
show 4 more comments
Try:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -name "name to match" -delete
Edit - first code is not abswer for question, try this:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -exec grep -l --null "pattern in file" {} + | xargs -0 rm
New contributor
1
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
You can't usexargs
in general on the output offind
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem withfind | xargs
)
– Stéphane Chazelas
yesterday
1
No, I meant-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOSgrep
should also support GNU's--null
option so-exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).
– Stéphane Chazelas
yesterday
1
Yes. It's correct (there are some race condition issues linked to usingxargs rm
instead of-delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).
– Stéphane Chazelas
yesterday
|
show 4 more comments
Try:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -name "name to match" -delete
Edit - first code is not abswer for question, try this:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -exec grep -l --null "pattern in file" {} + | xargs -0 rm
New contributor
Try:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -name "name to match" -delete
Edit - first code is not abswer for question, try this:
find ~/Library/MobileDevice/Provisioning Profiles/ -type f -exec grep -l --null "pattern in file" {} + | xargs -0 rm
New contributor
edited yesterday
New contributor
answered yesterday
MatejMatej
365
365
New contributor
New contributor
1
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
You can't usexargs
in general on the output offind
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem withfind | xargs
)
– Stéphane Chazelas
yesterday
1
No, I meant-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOSgrep
should also support GNU's--null
option so-exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).
– Stéphane Chazelas
yesterday
1
Yes. It's correct (there are some race condition issues linked to usingxargs rm
instead of-delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).
– Stéphane Chazelas
yesterday
|
show 4 more comments
1
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
You can't usexargs
in general on the output offind
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem withfind | xargs
)
– Stéphane Chazelas
yesterday
1
No, I meant-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOSgrep
should also support GNU's--null
option so-exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).
– Stéphane Chazelas
yesterday
1
Yes. It's correct (there are some race condition issues linked to usingxargs rm
instead of-delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).
– Stéphane Chazelas
yesterday
1
1
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
This is searching for a filename pattern. OP wants to find files which contain a certain string/text.
– Michael D.
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
@MichaelD. Oh, you are right, my bad.
– Matej
yesterday
You can't use
xargs
in general on the output of find
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem with find | xargs
)– Stéphane Chazelas
yesterday
You can't use
xargs
in general on the output of find
, but especially here, it won't work as the paths of the files contain spaces (all whitespace, quotes backslashes are a problem with find | xargs
)– Stéphane Chazelas
yesterday
1
1
No, I meant
-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOS grep
should also support GNU's --null
option so -exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).– Stéphane Chazelas
yesterday
No, I meant
-exec grep -q pattern {} ; -print0 | xargs -0 rm
. macOS grep
should also support GNU's --null
option so -exec grep -l --null pattern {} + | xargs -0 rm
should also work (and avoid running one grep per file).– Stéphane Chazelas
yesterday
1
1
Yes. It's correct (there are some race condition issues linked to using
xargs rm
instead of -delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).– Stéphane Chazelas
yesterday
Yes. It's correct (there are some race condition issues linked to using
xargs rm
instead of -delete
, but probably not worth working around here as we're presumably not removing files from a directory under control of potentially malicious actors).– Stéphane Chazelas
yesterday
|
show 4 more comments
This is searching for string err
in all files in /var/log/
recursive.
I'm not sure if cut
, uniq
and xargs
is available on Mac and this is not using find
.
grep -r "err" /var/log/ | cut -d: -f1 | uniq | xargs echo
Replace echo
with rm
to delete the files.
'find',cut
,uniq
andxargs
are standard Unix utilities available on any Unix platform.
– Kusalananda
yesterday
add a comment |
This is searching for string err
in all files in /var/log/
recursive.
I'm not sure if cut
, uniq
and xargs
is available on Mac and this is not using find
.
grep -r "err" /var/log/ | cut -d: -f1 | uniq | xargs echo
Replace echo
with rm
to delete the files.
'find',cut
,uniq
andxargs
are standard Unix utilities available on any Unix platform.
– Kusalananda
yesterday
add a comment |
This is searching for string err
in all files in /var/log/
recursive.
I'm not sure if cut
, uniq
and xargs
is available on Mac and this is not using find
.
grep -r "err" /var/log/ | cut -d: -f1 | uniq | xargs echo
Replace echo
with rm
to delete the files.
This is searching for string err
in all files in /var/log/
recursive.
I'm not sure if cut
, uniq
and xargs
is available on Mac and this is not using find
.
grep -r "err" /var/log/ | cut -d: -f1 | uniq | xargs echo
Replace echo
with rm
to delete the files.
answered yesterday
Michael D.Michael D.
1,577816
1,577816
'find',cut
,uniq
andxargs
are standard Unix utilities available on any Unix platform.
– Kusalananda
yesterday
add a comment |
'find',cut
,uniq
andxargs
are standard Unix utilities available on any Unix platform.
– Kusalananda
yesterday
'find',
cut
, uniq
and xargs
are standard Unix utilities available on any Unix platform.– Kusalananda
yesterday
'find',
cut
, uniq
and xargs
are standard Unix utilities available on any Unix platform.– Kusalananda
yesterday
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497666%2frelative-path-potentially-not-safe-error-with-find-delete-on-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown