LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2010, 04:53 PM   #16
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

Quote:
Originally Posted by tkmsr View Post
I am having certain directories also with the same name how do I put it here on command line.
Sorry but this is not clear. Please can you rephrase?
Quote:
Also I forgot to ask the meaning of {} at the end of the command.
As grail said, the find command substitutes the {} symbol with the names of the files or directories found, one at a time, then executes the specified command. Take in mind that the command is executed multiple times, one for each item and that the escaped semi-colon is necessary to make find recognize the end of the command itself.

On the other hand, if you want to execute the command only once - for all the items together (as if they were passed as multiple arguments on the command line) you have to put a + sign in place of the escaped semi-colon, e.g.
Code:
$ find / -wholename /home -prune -o -name lighttpd -exec echo rm {} +
rm /usr/local/sbin/lighttpd /usr/src/lighttpd-1.4.26/src/lighttpd /usr/src/lighttpd-1.4.x/src/lighttpd /var/run/lighttpd /var/cache/lighttpd /var/log/lighttpd /var/lighttpd /etc/cron.daily/lighttpd /etc/logrotate.d/lighttpd /etc/init.d/lighttpd /etc/lighttpd
 
Old 08-06-2010, 10:25 PM   #17
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by colucix View Post
Sorry but this is not clear. Please can you rephrase?
Actually there are some files with name lighttpd and some other are directories as lighttpd-1.4 so I am finding only lighttpd

Quote:
Originally Posted by colucix View Post
As grail said, the find command substitutes the {} symbol with the names of the files or directories found, one at a time,
I want to read more about it can you give some link.
I have read shell scripting tutorials many times but never came across such a usage.
Quote:
Originally Posted by colucix View Post
On the other hand, if you want to execute the command only once - for all the items together (as if they were passed as multiple arguments on the command line) you have to put a + sign in place of the escaped semi-colon, e.g.
Great tip.I never knew such a thing so it increases some value to my learning experience.Thanks.
 
Old 08-07-2010, 12:21 AM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
Actually there are some files with name lighttpd and some other are directories as lighttpd-1.4 so I am finding only lighttpd
This would mean now you need to do some globbing, eg.
Code:
find / -name "lighttpd*'
Quote:
I want to read more about it can you give some link.
Have you checked out 'man find'?
 
Old 08-07-2010, 12:47 AM   #19
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Yes man find I did.I mean to ask I need a link for the {} thin not the find command.
 
Old 08-07-2010, 01:07 AM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
Yes man find I did.I mean to ask I need a link for the {} thin not the find command.
I got that you needed information on {} symbols and hence the link was to look in the man page.

When I searched in 'man find' I found the following:
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.  See the EXAMPLES section for examples of the use of the -exec option.  The specified command is run once for each matched
              file.  The command is executed in the starting directory.   There are unavoidable security problems surrounding use of the -exec action; you  should  use
              the -execdir option instead.
 
2 members found this post helpful.
Old 08-07-2010, 01:41 AM   #21
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by grail View Post

-exec command ;
Thanks for pointing this
when I did man find in the bottom left most corner as search string I had typed
Code:
/{
to which it gave a message as
Code:
Invalid pattern  (press RETURN)
It is in exec this was not known to me.
Thanks.
 
Old 08-07-2010, 02:43 AM   #22
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
You may also check the online GNU findutils manual. The browser search function can be very useful if you read from the second link (HTML entirely on one web page).
 
Old 08-07-2010, 02:46 AM   #23
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
Quote:
Originally Posted by tkmsr View Post
Code:
/{
to which it gave a message as
Code:
Invalid pattern  (press RETURN)
When searching in man pages some characters need to be escaped:
Code:
/\{\}
 
Old 08-07-2010, 03:01 AM   #24
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
It is in exec this was not known to me.
Sorry ... my bad ... made the assumption that you knew that went together

I had the same search issue, but I cheated a little and just searched for the closing brace, so /} works
 
Old 08-07-2010, 05:15 AM   #25
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Ha ha no problem.But I am really curious to know as coculix mentioned /\{
so which character in man page we need to precede with \

Those html links are interesting I never came across any such thing.
 
Old 08-07-2010, 06:14 AM   #26
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
\ is the universal escape character in many things *nixish. Therefore \\ is the escape for \ to be searched for
 
Old 08-07-2010, 07:06 AM   #27
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
:) Well this I know.
Let me explain again
I searched in man page as
Code:
/{
and not
Code:
/\{
where as you searched
Code:
/}
and not
Code:
/\}
.
To get my result I need to type in
Code:
/\{
and where as you got it
only by
Code:
/}
.

So you should also have got result by search
Code:
/\}
and not
Code:
/}
.

Last edited by tkmsr; 08-07-2010 at 07:09 AM.
 
Old 08-07-2010, 08:56 AM   #28
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
ahhh ... with you now. The opening curly brace has special significance and so needs to be escaped. However, The closing curly brace is only
important if the opening one has been used, so the following is how it works:
Code:
/\{ - - for only the opening brace

/{ - -for only the closing brace

/\{\} - - for both the opening and closing
Hope that helps
 
Old 08-07-2010, 09:11 AM   #29
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Yea that did help but why is the opening curly brace so important ?
This thing I am curious to know.
 
Old 08-07-2010, 10:33 AM   #30
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Have a search on this page for the braces and see what they are intended for.
 
  


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
I need a script to Delete Selected BackupFiles and Restore selected backup file finalwar Linux - Newbie 3 07-20-2010 02:10 AM
[SOLVED] delete selected files from sftp dina3e Linux - Newbie 4 04-07-2010 02:43 AM
How to delete selected files? thomas2004ch Linux - Newbie 8 02-10-2010 11:50 AM
need to rsync only selected files (--files-from) also need to delete files on dest. ? BrianK Linux - General 5 10-22-2009 09:52 PM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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