-1

This may be a naive question, but I did not find the answer after searching online and on stackoverflow. I did not know the right keyword for finding the answer. Thanks in advance for giving out a pointer!

My question is on the '{}' in the following command:

find . -name "*.pyc" -exec rm -rf {} \;

Why we need {} and \; here?

yuyang
  • 1,511
  • 2
  • 15
  • 40
  • 4
    `man find` ~ `-exec command ;` All following arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered. The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a '\') or quoted to protect them from expansion by the shell. – Phil Jun 04 '14 at 06:42
  • 1
    http://unixhelp.ed.ac.uk/CGI/man-cgi?find – Ocaso Protal Jun 04 '14 at 06:43
  • 1
    This question appears to be off-topic because it is quickly solved via RTFM – Phil Jun 04 '14 at 06:45

4 Answers4

1

{} means the found files or directories through find command. \; needed when use -exec option with find which denotes the command termination.

find . -name "*.pyc" -exec rm -rf {} \;

Find the files or directories where their names ended with .pyc only inside the current directory and perform the remove operation on the found files or directories.

Rishi Raj
  • 3
  • 3
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
1

when searching man find google says: http://unixhelp.ed.ac.uk/CGI/man-cgi?find

If you again search for {} there you will see the explanation. You could also issue man find in your console.

Quamis
  • 10,924
  • 12
  • 50
  • 66
1

The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find.

Abhineet
  • 5,320
  • 1
  • 25
  • 43
0

It represents the found filename.

Klemen Tusar
  • 9,261
  • 4
  • 31
  • 28