어떻게 사용할 수있는 grep
단지 파일 이름 (아무 인라인 경기) 리눅스를 보여?
나는 보통 다음과 같은 것을 사용하고 있습니다 :
find . -iname "*php" -exec grep -H myString {} \;
파일 이름 (경로 포함)을 얻을 수 있지만 일치하지 않는 방법은 무엇입니까? 사용해야 xargs
합니까? grep
맨 페이지 에서이 작업을 수행 할 방법을 찾지 못했습니다 .
답변
표준 옵션 grep -l
(소문자 L)이이를 수행 할 수 있습니다.
로부터 유닉스 표준 :
-l
(The letter ell.) Write only the names of files containing selected
lines to standard output. Pathnames are written once per file searched.
If the standard input is searched, a pathname of (standard input) will
be written, in the POSIX locale. In other locales, standard input may be
replaced by something more appropriate in those locales.
-H
이 경우 에도 필요하지 않습니다 .
답변
로부터 grep(1)
매뉴얼 페이지
-l, --files-with-matches Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)
답변
간단한 파일 검색을 위해 grep -l
및 -r
옵션을 사용할 수 있습니다.
grep -rl "mystring"
모든 검색은 grep에 의해 수행됩니다. 물론 다른 매개 변수에서 파일을 선택 해야하는 경우 올바른 해결책을 찾으십시오.
find . -iname "*.php" -execdir grep -l "mystring" {} +
이 execdir
옵션은 각 디렉토리마다 각 grep 명령을 작성하고 파일 이름을 하나의 명령 ( +
)으로 연결합니다.
답변
귀하의 질문 파일 이름 (경로 포함)을 얻는 방법
구문 예제는 find입니다. -iname “* php”-exec grep -H myString {} \;
내 명령 제안
sudo find /home -name *.php
Linux OS에서이 명령의 출력 :
compose-sample-3 / html / mail / contact_me.php
경로가 포함 된 파일 이름이 필요하므로 즐기십시오!