Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a subcommand inside find exec

Tags:

shell

How can I run a subcommand inside find's exec? For example, if I want to get the filename only from the full path and print it, I would fire,

find ./ -name "*.csv" -exec echo $(basename {}) \;

where the echo is parent command of child command basename.

But the result is same as this,

find ./ -name "*.csv" -exec echo {} \;

What should I do ?

like image 855
JohnG Avatar asked Dec 12 '12 06:12

JohnG


1 Answers

This is what you are looking for:

find . -name "*.csv" -exec sh -c 'echo $(basename "$1")' sh {}  \;
like image 117
jlliagre Avatar answered Sep 30 '22 00:09

jlliagre