What does rm {} + do?

7,676

Solution 1

The {} bit is the placeholder for the exec command. Whatever files are found by find are inserted in place of the brackets. The + means to build up a long list of the found files and call the exec on all of them at once instead of one at a time, like the more traditional -exec {} \; variant.

Solution 2

From man find:

   -exec command {} +
   This variant of the -exec option runs the specified  command  on
   the  selected  files, but the command line is built by appending
   each selected file name at the end; the total number of  invoca-
   tions  of  the  command  will  be  much  less than the number of
   matched files.  The command line is built in much the  same  way
   that  xargs builds its command lines.  Only one instance of '{}'
   is allowed within the command.  The command is executed  in  the
   starting directory.

So it will call the command:

rm [filename1] [filename2] [...] [lastfilename]

If there are more files than can fit in the argument list rm will be called more than once. (This is what xargs does.)

Without the {} + it would just call rm a bunch of times with no arguments.

Share:
7,676

Related videos on Youtube

Bert Smith
Author by

Bert Smith

Updated on September 17, 2022

Comments

  • Bert Smith
    Bert Smith over 1 year

    As in

    find -L /etc/ssl/certs/ -type l -exec rm {} +
    

    So it finds all broken symlinks and deletes them. But how exactly do I interpret the {} + part?

    • wfaulk
      wfaulk over 14 years
      I didn't know about the "+" variant. Thanks for pointing it out!