LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   EXEC command in Linux (https://www.linuxquestions.org/questions/linux-newbie-8/exec-command-in-linux-4175467971/)

richa07 07-01-2013 03:44 AM

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

Madhu Desai 07-01-2013 04:17 AM

Linux find exec command examples

druuna 07-01-2013 04:33 AM

Quote:

Originally Posted by richa07 (Post 4981574)
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))

rtmistler 07-01-2013 10:31 AM

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/

rknichols 07-01-2013 01:32 PM

Quote:

Originally Posted by rtmistler (Post 4981789)
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.

David the H. 07-03-2013 12:41 PM

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.


All times are GMT -5. The time now is 11:31 PM.