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

Reference: https://stackoverflow.com/a/11392505

Last updated