LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 10-29-2017, 09:25 AM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Question on the placement of {} when using -exec with find


So I'm still not clear on what this means when using find and -exec

Code:
{}
Is this some sort of regular expression?

Also I've noticed that {} has to be placed in different locations in order for it to work correctly, for example.

Code:
useradd -c "mary" mary 

find /-user mary

find / -user mary -exec rm -rf {} \;

*** VS ***

Code:
useradd -c "mary" mary

find / -user mary 

mkdir -p /root/mary_backup

find / -user mary -exec -cp rpfv {} /root/mary_backup \;
For the 1st example {} comes right after the rm -rf, and before the \;.

For the 2nd example, {} comes right after the command cp -rpfv but before the \;. I'm not sure why.

thanks
 
Old 10-29-2017, 09:29 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
man find:

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, [...]
 
Old 10-29-2017, 10:36 AM   #3
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
In other words, {} represents the found file name where it needs to go in the command to be executed.
 
Old 10-29-2017, 11:40 AM   #4
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
I've never had a great understanding of this, what does argument mean?

Quote:
Originally Posted by ntubski View Post
man find:

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, [...]
 
Old 10-29-2017, 11:54 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by JockVSJock View Post
I've never had a great understanding of this, what does argument mean?
when you run a command like
Code:
rm -rf foo
You are passing -rf and foo as the arguments (also known as parameters) to the command rm.
 
1 members found this post helpful.
  


Reply

Tags
find, regular expression, {}



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
[SOLVED] question on find -exec timl Linux - Software 6 04-28-2016 06:52 AM
Script question with find -exec linuxbird Linux - Newbie 12 05-15-2011 03:21 AM
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
Shell Scripting Question (mv via find/-exec) ddenton Linux - General 3 11-21-2008 08:10 AM
find -exec question eantoranz Linux - General 1 06-26-2004 10:57 AM

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

All times are GMT -5. The time now is 02:17 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