LinuxQuestions.org
Help answer threads with 0 replies.
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 07-01-2013, 04:44 AM   #1
richa07
LQ Newbie
 
Registered: Jun 2013
Location: India
Posts: 8

Rep: Reputation: Disabled
EXEC command in Linux


Hi
Can anybody tell me what is the use of EXEC command and how we can use it, i checked online but still have confusion with this.

like in this below command what EXEC will do :
find . -type f -name "*19201020320*" -exec cp '{}' /tmp \;

Thanks in advance

Last edited by richa07; 07-01-2013 at 04:52 AM.
 
Old 07-01-2013, 05:17 AM   #2
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
Linux find exec command examples
 
Old 07-01-2013, 05:33 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Quote:
Originally Posted by richa07 View Post
Hi
Can anybody tell me what is the use of EXEC command and how we can use it, i checked online but still have confusion with this.

like in this below command what EXEC will do :
find . -type f -name "*19201020320*" -exec cp '{}' /tmp \;

Thanks in advance
Just to make sure: The exec "command" you are talking about is not a command but an option that belongs to the find command. mddesai posted a link, here's another: Part 5: Using -exec option and xargs with find

There's also a command called exec (16.1. Using exec (ABSG))
 
Old 07-01-2013, 11:31 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,844
Blog Entries: 12

Rep: Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010
It will execute a copy command of the found files into the /tmp directory. Termination of the exec command is the \; sequence. My more common usage is this, although I'm sure there are newer commands which can do similar results.

Code:
find . -name "*.[ch]" -exec grep <pattern> {} /dev/null \;
This finds all source files that are .c or .h extensions and greps them for my pattern.

And I don't know the full explanation, but without the /dev/null, I get the grep results only and don't see the files which they are located in. With the /dev/null, I get the found files, including fully resolved pathnames; which is more useful.

Further I'm not sure EXEC is a shell command, but instead solely an extension to the find(1) command.

Given the example you cited, this is the best guess, which other's have also responded too. But also realize that there is a family of exec(3) functions which are used in programs to execute commands. A bit lengthy, and covers way more than the fundamentals for exec(), but here are some notes on what that's used for: http://www.linuxquestions.org/questi...ocesses-35540/
 
Old 07-01-2013, 02:32 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,585

Rep: Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569
Quote:
Originally Posted by rtmistler View Post
And I don't know the full explanation, but without the /dev/null, I get the grep results only and don't see the files which they are located in.
By default, grep does not display the file name if there is only one file to search. Adding /dev/null supplies an additional file name, which of course will never contain a match. You could also just use grep's "-H" (--with-filename) option (note: upper case H) to ensure that a file name will be printed.
 
Old 07-03-2013, 01:41 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
The -H option prints the filename and the matching lines. If you want the filename only, use the -l option.

I just finished posting more details about using find and grep in the OP's other thread about listing folders.
 
  


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
exec command help vicky007aggrwal Linux - Newbie 4 10-28-2012 08:49 AM
exec command travix Linux - Newbie 2 09-15-2012 01:59 PM
Linux exec command grob115 Programming 4 05-02-2011 07:15 AM
exec command not working suruchi Linux - Software 2 06-12-2006 02:02 AM
exec bash command bendeco13 Linux - General 6 10-31-2004 04:50 PM

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

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