Reputation: 95
I've been trying to replace the content of a file with {}
with a command.
The thing is that I want to do that if the file hasn't been changed since 6am so I'm using this command :
sudo find /path/to/file -type f ! -newermt '06:00:00' -exec echo "{}" > '/path/to/file' \;
The problem is that with the find command the {}
are replaced with the path of the file that has been found, and I tried using quotes, or doube quotes or anti-slash but I can't get it to work properly...
Does anybody know the correct syntax ?
Thanks
Upvotes: 2
Views: 100
Reputation: 27255
At least in GNU find I couldn't find a way to stop replacing {}
with the path. Therefore, your question boils down to »*How to print {}
without using the substring "{}
"*«.
Here are some examples that can be used inside find -exec
:
printf %s%s\\n { }
sh -c 'echo {""}'
Upvotes: 1
Reputation: 2562
With the GNU coreutils echo
command, you can use character encoding like that :
sudo find /path/to/file -type f ! -newermt '06:00:00' \
-exec echo -e "\\0173\\0175" > '/path/to/file' \;
Explanation: We use the octal ascii code for the curly braces, \\0173
for '{' and \\0175
for '}' with the flag -e
for the echo
command. That way, find
will not see a pattern to put the found filenames, and the echo
command will output the curly braces ('{}').
Upvotes: 2