find and execute a command code example

Example 1: find and execute a command

find ... | while read -r file; do
    echo "look at my $file, my $file is amazing";
done

Example 2: find and execute a command

multiple_cmd() { 
    tail -n1 $1; 
    ls $1 
}; 
export -f multiple_cmd; 
find *.txt -exec bash -c 'multiple_cmd "$0"' {} \;

Example 3: find and execute a command

find . -type d -exec sh -c "echo -n {}; echo -n ' x '; echo {}" \;

Example 4: find and execute a command

find . -name "*.txt" -exec echo {} \; -exec grep banana {} \;