반응형
grep을 사용하여 Linux에서 파일 이름 만 표시하려면 어떻게해야합니까?
grep
Linux에서 파일 이름 (인라인 일치 없음) 만 표시 하려면 어떻게 해야합니까?
나는 일반적으로 다음과 같은 것을 사용하고 있습니다.
find . -iname "*php" -exec grep -H myString {} \;
어떻게 파일 이름 (경로 포함)을 얻을 수 있지만 일치하지 않습니까? 사용해야 xargs
합니까? 내 grep
man 페이지 에서이 작업을 수행하는 방법을 보지 못했습니다 .
표준 옵션 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가 올바른 솔루션입니다.
find . -iname "*.php" -execdir grep -l "mystring" {} +
이 execdir
옵션은 각 디렉토리마다 각 grep 명령을 빌드하고 파일 이름을 단 하나의 명령 ( +
)으로 연결합니다.
참고 URL : https://stackoverflow.com/questions/6637882/how-can-i-use-grep-to-show-just-filenames-on-linux
반응형
'programing tip' 카테고리의 다른 글
Firefox 또는 Chrome에서 수동으로 HTTP POST 요청을 실행하려면 어떻게합니까? (0) | 2020.09.28 |
---|---|
'ArrayList 변환 (0) | 2020.09.28 |
Java 클래스 경로 내의 디렉토리에있는 모든 jar 포함 (0) | 2020.09.28 |
동시성과 병렬성의 차이점은 무엇입니까? (0) | 2020.09.28 |
인라인 CSS에서 a : hover를 작성하는 방법은 무엇입니까? (0) | 2020.09.28 |