I want to list files having EXACT strings like "hello", "how" and "todo" from a directory (which is having multiple directories). Also I want to list c(.c) and cpp (.cpp) files only. I have tried with grep -R
(grep -R "hello" /home
) but not satisfied. Please help me to enhance my grep -R
command or any alternate way. Thanks in advance.
if you want to find files, a good start is usually to use find
.
if you want to find all .cpp
and .-c
files that contain the strings "hello", "how" or "todo" in their content, use something like:
find /home \( -name "*.c" -or -name "*.cpp" \) \
-exec egrep -l "(hello|how|todo)" \{\} \;
if instead you want to find all .cpp
and .-c
files that contain the strings "hello", "how" or "todo" in their filenames, use something like:
find /home \
\( \( -name "*.c" -or -name "*.cpp" \) \
-and \
\( -name "*hello*" -or -name "*how*" -or -name "*todo*" \) \
\)
there is a bit of quoting (using \
) involved, as ()
, {}
and ;
are considered special characters by the shell...
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加