macos – Simple Mac Bash Script (Find/Replace) – Education Career Blog

First, any support and help on this is largely appreciated.

I’m trying to write a simple Bash script (completely new to this) to replace a file in a given directory.

Basically, I need to write a script to replace the safari preference file, here’s what I have..and what’s not working for that matter:

find /Files/ -iname "" - print0 | xargs -I{} -0 -1 cp file /Users/{}/Library/Preferences

It errors out with the following:

find: -: unknown option
xargs: illegal option -- 1

Any thoughts, ideas, are greatly appreciated.



I couldn’t understand what exactly you want to accomplish with this. As I understand, you would have this “” in /Files/, is that correct?

And then you want to get this file into some place that, I assume, overwrites Safari’s current plist file. Assuming you take ghostdog74’s correct advice and remove the space between - print0, thus turning it into -print0, and then remove the -1 from xargs, as it doesn’t exist, this is what would happen:

find would find your file in /Files/, and xargs would run this:
cp file /Users/; It would then die, since it would not find a file called “file” or a directory named “/Users/”.

That’s most likely not what you want. 🙂

If you just want to copy the file to somewhere, why don’t you just do cp /Files/ ~/Library/Preferences/ ?

Do you really need find and xargs in this case? Could you clarify?


No space between - print0. and since -1 is not an option, remove it and see.

find /Files/ -iname "" -print0 | xargs -I{} -0 cp file /Users/{}/Library/Preferences

Leave a Comment