How to use -exec option in find command
You're almost there. You need a \;
on the end to let find know where the end of the command is.
find /opt/compiz-built/share/gconf/schemas -exec gconftool-2 --install-schema-file={} \;
For commands that can take multiple arguments at a time (eg if you wanted to just stat
each filename) you can use \+
instead. This will build a compound argument which can execute a faster because it doesn't fork out for every single file:
find . -exec stat {} \+
That won't work here for your example though.
Just a test harness to highlight that quotes aren't required:
$ mkdir 1 2 1\ 2 # makes three directories
$ touch {1,2}/single # puts a file in each of the two singles
$ touch 1\ 2/COMBO # puts a file in the dir with a space
$ find -type d -exec ls {} \;
1 1 2 2
single
single
COMBO
If it wasn't handling quoting for us, we'd see this instead of COMBO:
1:
correct
2:
correct
Related videos on Youtube
xiaodongjie
Updated on September 18, 2022Comments
-
xiaodongjie over 1 year
I wanna solve some problems in
compiz
with my brain and hands.By the way I entered following command to build
compiz
from source in Ubuntu 12.04find /opt/compiz-built/share/gconf/schemas -exec gconftool-2 --install-schema-file={};
I referred that command at http://www.brazzi64.net/blog/building-compiz-from-source-in-ubuntu-12-04/
And following message is shown.
How to use
-exec
option in find command, I guess that it's my mistake. -
terdon almost 10 years+1. No need for quotes,
find
deals with spaces (and other weirdness) internally. -
Oli almost 10 yearsEven on arguments for things? Edit: Just tested it and yeah, it does seem to work without quotes. That's pretty fancy.
-
terdon almost 10 yearsI know right? I used to quote the darn thing all the time until someone pointed it out to me.
-
Sparhawk almost 10 yearsAlso,
-execdir
is preferred over-exec
for security reasons (seeman find
).