[SunHELP] Re: help with the 'find' command

Robert Novak rnovak at indyramp.com
Wed Mar 6 20:18:48 CST 2002


On Wed, 6 Mar 2002, Solaris Neophyte wrote:

> I am completely confused as to what the {} do with the find comand.
> 
> the explanation is this: "A set of braces, {}, delimits where the 
> file name is passed to the command from the prceding expressions."

Simply, the {} is replaced by the appropriately-qualified filename that
the preceding expressions matched. If the expressions match more than one
filename, then the command is executed once for each filename.

> an example they give is the following:
> 
> $ find ~ -name core -exec rm {} \;

In this case, it finds every file (actually, every file or directory)
named core, starting from the current user's home directory, and executes
"rm filename" on each. So you might have:

	% find ~ -name core -print
	/home/me/mail/core
	/home/me/src/rsync/src/core
	/home/me/workingdir/15x/core
	% 

In this case, the example above with the -exec would execute the following
commands for you:

	rm /home/me/mail/core
	rm /home/me/src/rsync/src/core
	rm /home/me/workingdir/15x/core

Does that make more sense?

Here's another example. Let's say you find some files in your home
directory that are owned by root instead of by you. You could do this to 
fix that:

	# find ~realuser -user root -exec chown realuser {} \;

You can do multiple execs in a line too...

	# find ~realuser -user root -exec chown realuser {} \; \
		-exec chmod 600 {} \; -print

And if you want to see a list of the affected files, simply put a "-print"
on the end of the command (or "-ls" to show the full dir listing of the
files). 

Hope this helps a bit.

Rob

Robert Novak, Indyramp Consulting * rnovak at indyramp.com * indyramp.com/~rnovak
	"I don't want to doubt you, Know everything about you
      I don't want to sit Across the table from you Wishing I could run."



More information about the SunHELP mailing list