LinuxQuestions.org
Visit Jeremy's Blog.
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 06-01-2010, 11:41 AM   #1
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
find command with exec


Code:
find /var/ftp/mp3 -name "*.mp3" -type f -exec chmod 644 {} \;
Why is "\" used?
 
Old 06-01-2010, 11:45 AM   #2
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Original Poster
Rep: Reputation: 65
And what's the difference with this:
Code:
find /var/ftp/mp3 -name "*.mp3" -type f -exec chmod 644 '{}' \;
 
Old 06-01-2010, 12:35 PM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

the single quotes and the backslash are used to protect the braces and the semicolon from shell expansion. See the man and info pages for more info on this.
 
Old 06-01-2010, 01:01 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by crts View Post
the single quotes and the backslash are used to protect the braces and the semicolon from shell expansion. See the man and info pages for more info on this.
More specifically the braces and semicolon are shell metacharacters as listed here. The special meaning of a metacharacter is removed when it is "escaped" (by putting a "\" in front of it) or enclosed in single quotes.

The ";" is used to separate lists of commands as explained here. In practice it is not much used because a line end does equally well.

The "{ }" is used to group commands as explained here. When it is empty -- as used in find commands -- it does not need to be escaped or quoted.
 
1 members found this post helpful.
Old 06-01-2010, 01:21 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by catkin View Post
The ";" is used to separate lists of commands as explained here. In practice it is not much used because a line end does equally well.
Umm ... in this case (the escaped version) it's part of the
find command. It terminates the -exec ... and in that context
it's not only frequently used, it's indispensable.


Cheers,
Tink
 
Old 06-01-2010, 01:25 PM   #6
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Lightbulb

Quote:
Originally Posted by catkin View Post
More specifically the braces and semicolon are shell metacharacters as listed here. The special meaning of a metacharacter is removed when it is "escaped" (by putting a "\" in front of it) or enclosed in single quotes.

The ";" is used to separate lists of commands as explained here. In practice it is not much used because a line end does equally well.

The "{ }" is used to group commands as explained here. When it is empty -- as used in find commands -- it does not need to be escaped or quoted.
Good information.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
find with -exec: no command output David the H. Linux - Software 5 01-03-2008 01:53 AM
does "find -exec" not recognize built-in command? yaru22 Linux - General 1 06-30-2006 10:35 AM
using multiple -exec commands in a single find command? Bluemilk Linux - Newbie 4 03-19-2006 10:46 AM
redhat 9.0 how to use the command 'find' with the action -exec arvin_shu Linux - Newbie 3 11-30-2005 07:09 AM

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

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