Site icon LinuxCommands.site

How to search all files with specific text on Linux?

In daily development, we often encounter the situation of searching specific content.

How to search all files with specific content in Linux system?

In this case, Linux grep command and Linux find command will be used.

Use the grep command to search for specific content

➜ grep -Rn 'ylspirit' .

# OR

➜ grep -e 'ylspirit' -Rn .

Search only for specific extensions

Search only for “. sh” extensions

➜ grep -e 'ylspirit' -Rn --include=\*.sh .

Use the find and grep to search for specified content

➜ find . -type f -exec grep -Hn 'ylspirit' {} \;

# OR

➜ find . -type f | xargs grep -Hn 'ylspirit'

Search only for specific extensions

➜ find . -name "*.sh" -type f -exec grep -Hn 'ylspirit' {} \;

Exit mobile version