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

おすすめ記事