0

but a question what does this command do? I know find command but about options no,like expression in quotation and also -exec and ...

find /var -name "[0-9]*test[A-Z]" -exec  {} /root/{}';'
1
  • 1
    Did you find this command somewhere or did you run it yourself? What are you trying to do?
    – d a i s y
    May 31 '18 at 10:27
3

find /var instructs find to start the search at the directory /var.

-name "[0-9]*test[A-Z]" is the search pattern to instruct find to return only files/folders that match the pattern "[0-9]*test[A-Z]". If you do not quote the search string, your shell would expand that search pattern and would try to execute the result. By quoting the search pattern you pass it as an argument to find /var -name.

The -exec... part of the original question has an syntax error and it should be -exec {} /root/{} ';' (note the space before ';' as commented by dessert and daisy).
It instructs find to execute the following arguments, where {} is replaced by the search result of find. You normally should quote those as well to prevent shell expansion.

Lastly, the ';' defines how the -exec section should handle the search results when executing the command. ';' instructs find to run the command of -exec for each single find result. When using '+' instead the -exec command is run with all find results expanded. This also has to be quoted or escaped to prevent the shell of expanding it and making an argument to find...-exec.

A little example that illustrates the difference between ";" and "+" is as follows.

[user@localhost test]$ find . -name "[0-9]*test[A-Z]" -exec echo "{}" ";"
./12ltestA
./1ltestA
[user@localhost test]$ find . -name "[0-9]*test[A-Z]" -exec echo "{}" "+"
./12ltestA ./1ltestA
3
  • Isn't it -exec {} /root/{} ';'?
    – d a i s y
    May 31 '18 at 10:19
  • In the original post yes, but I just wanted to illustrate the difference between ;' and +`.
    – Thomas
    May 31 '18 at 10:25
  • 1
    @dessert: could be please elaborate your concerns? Not sure what you are referring to?
    – Thomas
    May 31 '18 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.