このクエリでマルチレベルシンボリックリンクをどのように回避できますか?

このクエリでマルチレベルシンボリックリンクをどのように回避できますか?

わかりましたワイヤー見つかった内容を修正しようとしましたが-mindepth 15失敗しました。

find -L $HOME -type f -name "*.tex" \
   -exec fgrep -l "janne" /dev/null {} + | vim -R -

失敗した試み

find -L $HOME -type f -mindepth 15 -name "*.tex" \
   -exec fgrep -l "janne" /dev/null {} + | vim -R -
  • find -Lそれについてここ

その頑丈な

Vim: Reading from stdin...
find: ‘/home/masi/LOREM’: Too many levels of symbolic links

シンボリックリンクの視覚化が成功しませんでした。システムのシンボリックリンクディレクトリとファイルのみを表示したいのですが、すべてのファイルが提供されます。

tree -l

Law29の提案

# include symlinks
find "$1" -type l -name "$2*" -print0 \
    | xargs -0 grep -Hr --include "*.tex" "$2" /dev/null {} + | vim -R -

出力に失敗しましたが空にすることはできません。

Vim: Reading from stdin...
grep: {}: No such file or directory
grep: +: No such file or directory

システムの特徴

masi@masi:~$ ls -ld -- "$HOME" /home/masi/LOREM 
drwxr-xr-x 52 masi masi 4096 Aug 16 16:09 /home/masi
lrwxrwxrwx  1 masi masi   17 Jun 20 00:27 /home/masi/LOREM -> /home/masi/LOREM/

masi@masi:~$ type find
find is /usr/bin/find

masi@masi:~$ find --version
find (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2) 

システム:Linux Ubuntu 16.04 64ビット
スレッドスクリプトの場合:ここ
検索: 4.7.0
Grep: 2.25
適用find:haetex ここ

ベストアンサー1

次の文字列で終わり、次の文字列を含むすべてのファイル$HOME(シンボリックリンクを介して参照されるファイルを含む)を表示したい場合:.texjanne

find -L "$HOME" -type f -name '*.tex' -exec grep -l 'janne' {} + 2>/dev/null | vim -R -

$HOME文字列を含むファイルに対応する名前の下にある*.texシンボリックリンクのみを表示したい場合janne

find -L "$HOME" -xtype l -name '*.tex' -exec grep -l 'janne' {} + 2>/dev/null | vim -R -

「シンボルリンクレベルが多すぎます」というエラーメッセージを回避する唯一の方法は、コンストラクタによって実行されたすべてのエラーを削除することです2>/dev/null

どちらの場合も、find動詞はすでに移動したファイルやディレクトリを移動しません。訪問した場所を覚えて、ファイルシステムツリーの対応する部分を自動的にクリーンアップします。例えば、

mkdir a a/b a/b/c
cd a/b/c
ln -s ../../../a

# Here you can ls a/b/c/a/b/c/a/b/...

# But find will not continue for very long
find -L a
a
a/b
a/b/c
find: File system loop detected; ‘a/b/c/a’ is part of the same file system loop as ‘a’.

おすすめ記事