I found the following awesome little script at link
$ find /home/bruno/old-friends -type f -exec sed -i
's/ugly/beautiful/g' {} ;
But I really do not understand the final bit
{} ;
Could someone please explain??
Thanks!
I found the following awesome little script at link
$ find /home/bruno/old-friends -type f -exec sed -i
's/ugly/beautiful/g' {} ;
But I really do not understand the final bit
{} ;
Could someone please explain??
Thanks!
This is not exactly a sed
syntax problem, it's a find
syntax problem.
The {}
is a container that will replace the name of the file being processed by the sed
command.
If you use find
like this:
$ find . -type f -name *.py -exec head {} ;
This will find Python scripts and show you the head of each file. If you have three scripts in the current directory:
The {}
will contain each file name and execute the head
command on each file.
The -exec
argument needs a ;
at the end so it can recognize the end of the command arguments (sed
in this case) but, in order to protect ;
from expansion you need to escape it with the .
Remember that you can execute several commands at a time if you use the ;
:
$ ls; pwd;
This will list directories (ls
) and print your working directory (pwd
). The -exec
argument also needs the ;
. But since you don't want to confuse the ;
that separates commands with the ;
that is part of the -exec
argument of find
, you need to escape it with the .
Alternatively, you can use quotes around the ;
:
$ find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} ";"
I hope I made myself clear