Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
find -name "*.c" -exec ls -l {} /;


it says missing argument to '-exec',
why is that~?

Please tell me what is '/' at the end means as well, thanks
Posted
Updated 6-Jan-12 19:51pm
v3

The correct line would be:
find -name "*.c" -exec ls -l \{\} \;

or
find -name "*.c" -exec ls -l '{}' ';'

or
find -name "*.c" -exec ls -l '{}' \;

...
You see the pattern?

Reasoning?

  1. the shell splits the command line into chunks (1st chunk is the command, the rest are the individual arguments to the command)
  2. since the shell is a language in it self, it has some relevant punctuation and operator symbols - among others, { } and ; have a meaning to the shell
  3. since the find command also needs for some operations the {} and ; as own arguments, one must make sure that the {} and the ; are not interpreted by the shell, but are rather passed to the find command. There are two possibilities to achieve that: escaping or placing into a literal string.
  4. escaping is placing a \ before one character - the character then is not interpreted by the shell and is passed as-is (without leading \)
  5. '...' strings are passed as-is, after stripping off the leading and trailing single quote
  6. "..." strings get evaluated by the shell for variable substitution and other functions and only then are taken (by stripping off the quotes)

Note: If you want a text be passed unchanged to a command, use single quoted string ('...'). If you would place the {} or the ; into "{}" ";", they are interpreted by the shell and thus might not be passed unchanged to the find command.
 
Share this answer
 
Comments
Andreas Gieriet 6-Jan-12 20:10pm    
Experiment: if you place the echo command before your original find command line, what do you get?

E.g. echo find -name "*.c" -exec ls -l {} /;

If the output is not exactly

find -name *.c -exec ls -l {} ;

then your line is not properly escaped/put into strings.
You need to use the backslash to escape the semi-colon character thus:
JavaScript
find -name "*.c" -exec ls -l {} \;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900