find

A command-line utility that locates files based on some user-specified criteria and then applies some requested action on each matched object

Find files based on Regex

find . -type f -regextype posix-extended -regex '.*[0-9]\s.*'

Run command on each directory

Note: \( ! -name . \) avoids executing the command in the current directory.

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd" \;

Move files based on regex

Uses find’s -exec option, which replaces {} with each find result in turn, and runs the command you give it

find . -type f -regextype posix-extended -regex '.*[0-9]\s.*' -exec mv -t path_B {} +

On Mac, -regextype isn’t supported, so use -E:

find -E . -type f -regex '.*[0-9]\s.*' -exec mv -t path_B {} +

Copy files based on regex

Uses find’s -exec option, which replaces {} with each find result in turn, and runs the command you give it

find . -type f -regextype posix-extended -regex '.*[0-9]\s.*' -exec cp "{}" ../patch_B \;

On Mac, -regextype isn’t supported, so use -E:

find -E . -type f -regex '.*png' -exec cp "{}" ../logos \;