mlocate: 파일만 인쇄하는 방법

mlocate: 파일만 인쇄하는 방법

다음 버전의 위치 지정이 있습니다.

$ locate --version
mlocate 0.26
Copyright (C) 2007 Red Hat, Inc. All rights reserved.
This software is distributed under the GPL v.2.

This program is provided with NO WARRANTY, to the extent permitted by law.

예를 들어 특정 기본 이름을 가진 모든 파일(디렉토리 아님)을 찾으려고 하므로 python다음을 시도했습니다.

$ xargs -a <(locate -b '\python') -I{} file {} | sed -E '/directory|symbolic/d;s/:.*$//g'

그러면 예상한 결과가 정확하게 인쇄됩니다. 그러나 이것을 달성하는 효율적인 방법이 있는지 궁금합니다.

답변1

또한 명령은 현재 사용자가 액세스할 수 없는 파일을 출력합니다.

약간 더 짧은 솔루션은 다음과 같습니다.

locate -0b '\python' | perl -0nE 'say if -f'

하지만 액세스할 수 없는 파일은 인쇄되지 않습니다.

Bash를 사용하여 파일을 반복할 수도 있지만 약간 장황합니다.

locate -0b '\python' | while IFS= read -d '' -r f ; do
    [[ -f $f ]] && printf '%s\n' "$f"
done

관련 정보