find exec ls : No such file or directory

2019-07-15 11:56发布

问题:

I tried to execute:

find ~/ -name "*foo*" -exec "ls -la {}" \;

And it printed:

find: 'ls -la /home/users/MyUser/fooBar': No such file or directory

find: 'ls -la /home/users/MyUser/Barfoo': No such file or directory

Also ls is aliased to ls --color.

What kind of tricky trick happened here?

回答1:

The arguments of -exec should not be quoted. Remove the quotes after -exec. And -exec does not detect aliases so you need to pass the --color option to exec.



标签: bash shell find ls