私は自分の Web サイトのディレクトリ ツリー内のすべてのシンボリック リンクを見つけようとしています。 を使用してfind
これを行うことができることはわかっていますが、ディレクトリを再帰的にチェックする方法がわかりません。
このコマンドを試しました:
find /var/www/ -type l
… その後、その内容が/var/www
シンボリックリンクであることがわかったので、コマンドを次のように変更しました。
find -L /var/www/ -type l
実行にはしばらく時間がかかりますが、一致するものはありません。
サブディレクトリをチェックするにはどうすればいいでしょうか?
ベストアンサー1
これにより、ディレクトリが再帰的に走査され/path/to/folder
、シンボリック リンクのみが一覧表示されます。
ls -lR /path/to/folder | grep '^l'
シンボリック リンクもたどりたい場合は、find
コマンドを使用する必要がありますが、オプションを含める必要があります-L
。実際、find
マニュアル ページには次のように書かれています。
-L Follow symbolic links. When find examines or prints information
about files, the information used shall be taken from the prop‐
erties of the file to which the link points, not from the link
itself (unless it is a broken symbolic link or find is unable to
examine the file to which the link points). Use of this option
implies -noleaf. If you later use the -P option, -noleaf will
still be in effect. If -L is in effect and find discovers a
symbolic link to a subdirectory during its search, the subdirec‐
tory pointed to by the symbolic link will be searched.
When the -L option is in effect, the -type predicate will always
match against the type of the file that a symbolic link points
to rather than the link itself (unless the symbolic link is bro‐
ken). Using -L causes the -lname and -ilname predicates always
to return false.
次にこれを試してください:
find -L /var/www/ -type l
これはおそらく動作するでしょう: man ページでこのダイヤモンドを見つけましたfind
: オプションを使用している場合は、オプション-type
に変更する必要があります-xtype
:
l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.
それから:
find -L /var/www/ -xtype l