LinuxQuestions.org
Review your favorite Linux distribution.
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, 12:41 PM   #1
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

Rep: Reputation: 63
find command with exec


Code:
find /var/ftp/mp3 -name "*.mp3" -type f -exec chmod 644 {} \;
Why is "\" used?
 
Old 06-01-2010, 12:45 PM   #2
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

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

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
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, 02:01 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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, 02:21 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 02:25 PM   #6
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
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


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
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 05:35 PM
find with -exec: no command output David the H. Linux - Software 5 01-03-2008 02:53 AM
does "find -exec" not recognize built-in command? yaru22 Linux - General 1 06-30-2006 11:35 AM
using multiple -exec commands in a single find command? Bluemilk Linux - Newbie 4 03-19-2006 11:46 AM
redhat 9.0 how to use the command 'find' with the action -exec arvin_shu Linux - Newbie 3 11-30-2005 08:09 AM


All times are GMT -5. The time now is 10:45 AM.

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