Search Files

Search By Metadata

find <PATH> [-name <PATTERN>] [-type <FILE_TYPE>] [-delete]

<FILE_TYPE>: regular file (f), directory (d), symlink (l), etc.

Execute Command After "find"

# Run the CMD on each result
# Example CMD: `dirname {}`

find ... -exec <CMD> \;
# OR
find ... -print0 | xargs -0 -n1 -I {} <CMD>

# Run the CMD on the whole result

find ... -exec <CMD> \+
# OR
find ... -print0 | xargs -0 -I {} <CMD>

Differences between find -exec and find | xargs

Search By Content


-i: Case-insenstive -n: Display line number -r: Search the files recursively

Replace the Content in Multiple Files

sed -i 's/foo/bar/g' *

# or for BSD systems like MacOS
sed -i '.bak' 's/foo/bar/g' *


Last updated