How to run "find -exec <script> {}\;

24,464

You are missing the space between {} and ; :

find . -type d -exec ./script.sh {} \;
Share:
24,464

Related videos on Youtube

Ashwin
Author by

Ashwin

Updated on September 18, 2022

Comments

  • Ashwin
    Ashwin over 1 year

    I have a script that changes the properties of the files for a folder.

    Here is the example tree:

    dir 1
        --file 1
        --file 2
        --file 3
    dir 2
        --file 1
        --file 2
    dir 3
        --file 1
        --file 2
        --file 3
    

    I am running this command on the terminal for which I wan to run the shell script (script.sh) for every directory

    find . -type d -exec ./script.sh {}\;
    

    it does not run and errors' this:

    find: missing argument to `-exec'
    

    What am I missing here?

  • Olivier Dulac
    Olivier Dulac about 11 years
    I 1) added quotes around {} to avoid the shell to interpret {} as "launch something in the current shell" instead of the literral "{}" string. 2) added a space after it so that exec sees the expected ";" indicating the end of the exec command (that was the point making it "barf" to you) 3) put full path to the script to launch, to avoid confusion (reader and/or program) about which script is launched...