Log1k
Log1k

Reputation: 95

GNU find, keep {} as is with -exec

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

Answers (2)

Socowi
Socowi

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

Zilog80
Zilog80

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

Related Questions