We want to grep the corresponding files that including some fixed strings, and then output those files just only in ls -l format.
For example:
A) the following method with multiple -exec output both the grep and ls -l.
#
#
# find /usr/bin -type f -exec grep -Eil '#\!\/usr\/bin\/csh' {} \; -exec ls -l {} \; >scripts_csh_list 2>&1
#
#
#
# cat scripts_csh_list
/usr/bin/which
-r-xr-xr-x 1 bin bin 1191 Sep 06 2007 /usr/bin/which
#
#
B) But we want to the better method output only with ls -l ... , and then we failed via sh -c 'grep ... {}'
Notes: all the following different combined commands for the find -exec ... output the same failed result.
#
#
# find /usr/bin -type f -exec sh -c 'grep -Eil '\/usr\/bin\/csh' {} && ls -ltr {}' \; >scripts_csh_list 2>&1t
#
#
# tail -6 scripts_csh_list
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
#
#
#
# find /usr/bin -type f -exec sh -c ' grep -Eil '\/usr\/bin\/csh' {} ' \; >scripts_csh_list 2>&1
#
#
# tail -6 scripts_csh_list
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
#
#
# find /usr/bin -type f -exec sh -c ' grep -Eil '\/usr\/bin\/csh' "{}" ' \; >scripts_csh_list 2>&1
#
#
# tail -6 scripts_csh_list
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
#
#
#
# find /usr/bin -type f -exec sh -c " grep -Eil '\/usr\/bin\/csh' {} " \; >scripts_csh_list 2>&1
#
#
# tail -6 scripts_csh_list
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
#
#
#
# find /usr/bin -type f -exec sh -c " grep -Eil '\/usr\/bin\/csh' {} " \; >scripts_csh_list 2>&1
#
#
# tail -6 scripts_csh_list
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
grep: 0652-033 Cannot open {}.
#
#