LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-05-2007, 08:29 AM   #1
ddaas
Member
 
Registered: Oct 2004
Location: Romania
Distribution: Ubuntu server, FreeBsd
Posts: 474

Rep: Reputation: 30
exec {} \;


Hi there,
Could anyone explain me what are {} \; for at the end of the -exec ? What is exactly exec? Is is a shell command?

For example I could execute grep for any file which match a specific criteria. Something like this:
find / -type f -exec grep "something" {} \;


Thanks
 
Old 02-05-2007, 08:39 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The manual page of find explains this quite well: the string {} is replaced by the current file name being processed, that is all the files found by the find command are processed one by one and the {} construct tells to -exec which is the file to be processed now. All the argument after the -exec options are taken as the command to execute, until a literal ; is encountered. To pass literally a ; to -exec you have to escape it with a backslash in front of it, hence \;
 
Old 02-05-2007, 08:41 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
The find man page explains this quite succinctly:
Code:
-exec command ;
              Execute  command;  true  if 0 status is returned.  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.  The command  is  exe-
              cuted in the starting directory.
(Emphasis added) In essence, the {} means the file that's currently been found. Then \; (actually just a ;, but it needs to be escaped, hence the \) signifies the end of the command.
 
Old 02-05-2007, 09:02 AM   #4
ddaas
Member
 
Registered: Oct 2004
Location: Romania
Distribution: Ubuntu server, FreeBsd
Posts: 474

Original Poster
Rep: Reputation: 30
Many thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
exec cmd=perl... work but exec cgi doenst crions Slackware 5 12-09-2005 12:17 PM
cannot exec 'cc1plus' martine Mandriva 3 02-26-2005 11:11 AM
c++ exec fosh Programming 2 07-04-2004 10:44 AM
php exec devit Programming 4 04-08-2004 03:26 AM
cannot exec as person Linux From Scratch 5 12-19-2003 04:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration