How to use -exec option in find command

8,716

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
Share:
8,716

Related videos on Youtube

xiaodongjie
Author by

xiaodongjie

Updated on September 18, 2022

Comments

  • xiaodongjie
    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.04

    find /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
    terdon almost 10 years
    +1. No need for quotes, find deals with spaces (and other weirdness) internally.
  • Oli
    Oli almost 10 years
    Even on arguments for things? Edit: Just tested it and yeah, it does seem to work without quotes. That's pretty fancy.
  • terdon
    terdon almost 10 years
    I know right? I used to quote the darn thing all the time until someone pointed it out to me.
  • Sparhawk
    Sparhawk almost 10 years
    Also, -execdir is preferred over -exec for security reasons (see man find).