LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-01-2012, 01:12 PM   #16
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,559

Rep: Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127

When using the -exec flag in find, "{}" is essentially a keyword that inserts the name of the current file into your command. So if find finds the file "file1", "rm -i -r {}" becomes "rm -i -r file1".

As for the rest, -exec needs to be terminated in a semicolon to let find know where the end of the command is, but the semicolon is usually interpreted by the shell as an end of line terminator, so you have to escape it with a backslash.

According to find's man page:
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 executed in the starting directory.

Last edited by suicidaleggroll; 03-01-2012 at 01:13 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Could someone help me with looping in vb cobrien Programming 9 11-12-2010 09:17 AM
looping in script fw12 Programming 3 11-04-2009 04:48 PM
looping images? Cording44 Linux - Newbie 1 05-05-2009 10:34 AM
Not able to do looping in linux Amey Joshi Linux - Newbie 7 08-13-2008 04:25 AM
Looping a script Keentolearn Linux - Newbie 4 01-30-2007 04:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration