Zum Inhalt springen

Softlink/Problembehebung: Unterschied zwischen den Versionen

Aus Foxwiki
Die Seite wurde neu angelegt: „== Problembehebung == === find all files that link to this file === ==== It depends ==== if you are trying to find links to a specific file that is called <tt>foo.txt,</tt> then this is the only good way: find -L / -samefile path/to/foo.txt On the other hand, if you are just trying to find links to ''any'' file that happens to be named <tt>foo.txt</tt>, then something like find / -lname foo.txt or find . -lname \*foo.txt ignore leading pathname c…“
 
K Textersetzung - „line>“ durch „line copy>“
 
(12 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
== Problembehebung ==


=== find all files that link to this file ===
== Alle Links finden ==
Wenn Sie versuchen, Verknüpfungen zu einer bestimmten Datei namens foo.txt zu finden, dann ist dies der einzige gute Weg:
<syntaxhighlight lang="bash" highlight="1" line copy>
find -L / -samefile path/to/foo.txt
</syntaxhighlight>


==== It depends ====
Wenn Sie hingegen nur nach Verknüpfungen zu einer beliebigen Datei suchen, die zufällig foo.txt heißt, dann ist etwas wie
if you are trying to find links to a specific file that is called <tt>foo.txt,</tt> then this is the only good way:
<syntaxhighlight lang="bash" highlight="1" line copy>
find / -lname foo.txt
</syntaxhighlight>
oder
<syntaxhighlight lang="bash" highlight="1" line copy>
find . -lname \*foo.txt  
</syntaxhighlight>


find -L / -samefile path/to/foo.txt
das Problem mit den ignorierten führenden Pfadnamenkomponenten
* wunderbar gelöst. Vielen Dank an alle, die geantwortet haben.


On the other hand, if you are just trying to find links to ''any'' file that happens to be named <tt>foo.txt</tt>, then something like
Wie ich in einem gelöschten Kommentar angemerkt habe, können Sie -xtype l verwenden, um nur die Liste der Symlinks zu finden
find / -lname foo.txt
* Sie können eine Rekursion durchführen, da jede der Dateien, die auf foo.txt verweisen, selbst von einigen anderen Links referenziert werden kann ... z. B.: A->B->foo.txt, /tmp/C->B->foo.txt und weitere
or
find . -lname \*foo.txt  


ignore leading pathname components
Dies kann auch funktionieren, wenn Ihr Namensbestandteil ein übergeordnetes Verzeichnis ist, das im Link genannt wird, indem Sie
* problem solved beautifully. Thanks to all people that replied.
<syntaxhighlight lang="bash" highlight="1" line copy>
* As I commented on a deleted answer, you can use <tt>-xtype l</tt> to have find only list symlinks
find . -lname '*foo.dir*'
* you may want to recurse, as any of the files pointing to foo.txt may themselves be pointed-at by some other links... ex: A->B->foo.txt, /tmp/C->B->foo.txt, etc.
</syntaxhighlight>
* this can work too if your name component is a parent directory named in the link, by searching <tt>find . -lname '*foo.dir*'</tt> (matches e.g. <tt>file.txt -> ../foo.dir/file.txt</tt>)
* This answer is really helpful, thanks so much. By the way, if we want to get more info about the results of "find", we can pass the output of "find" to "ls": <tt>find -L /usr -samefile /usr/share/pyshared/lsb_release.py 2>/dev/null | xargs ls -al</tt>  


Find the inode number of the file and then search for all files with the same inode number
(entspricht z.&nbsp:B.&nbsp:file.txt -> ../foo.dir/file.txt)
$ ls -i foo.txt
41525360 foo.txt
$ find . -follow -inum 41525360


Alternatively, try the <tt>lname</tt> option of <tt>find</tt>, but this won't work if you have relative symlinks e.g. <tt>a -> ../foo.txt</tt>
Diese Antwort ist wirklich hilfreich, vielen Dank. Übrigens, wenn wir mehr Informationen über die Ergebnisse von "find" erhalten möchten, können wir die Ausgabe von "find" an "ls" übergeben
$ find . -lname /path/to/foo.txt*


If using a recent version of GNU find, you can also use the <tt>-samefile</tt> option with <tt>-L</tt> for the same effect, without having to look up the inode yourself
<syntaxhighlight lang="bash" highlight="1" line copy>
* But this will also find files on other file systems that happen to have the same inode number.  
find -L /usr -samefile /usr/share/pyshared/lsb_release.py 2>/dev/null | xargs ls -al
* If <tt>foo</tt> is a directory, use <tt>ln -di</tt>, in one line: <tt>find . -follow -inum $(ls -di foo.txt |cut -d" " -f1)</tt>
</syntaxhighlight>
Ermitteln Sie die Inode-Nummer der Datei und suchen Sie dann nach allen Dateien mit derselben Inode-Nummer


This answer is wrong
<syntaxhighlight lang="bash" highlight="1" line copy>
* A symlink doesn't have the same inode as its target. This will only work for a file inside a symlinked folder. But this is not what was asked.  
ls -i foo.txt
 
41525360 foo.txt
==== symlinks utility ====
; I prefer to use the <tt>symlinks</tt> utility, which also is handy when searching for broken symlinks.
find . -follow -inum 41525360
</syntaxhighlight>


Install by:
Alternativ können Sie die Option lname von find verwenden, aber dies funktioniert nicht, wenn Sie relative symbolische Links haben, z. B. a -> ../foo.txt
sudo apt install symlinks
<syntaxhighlight lang="bash" highlight="1" line copy>
Show all symlinks in current folder and subfolders:
find . -lname /path/to/foo.txt*
</syntaxhighlight>


symlinks -rv .* <tt>-r</tt>: recursive
Wenn Sie eine aktuelle Version von GNU find verwenden, können Sie auch die Option -samefile mit -L verwenden, um den gleichen Effekt zu erzielen, ohne selbst nach der Inode suchen zu müssen
* <tt>-v</tt>: verbose (show all symlinks, not only broken ones)
* Dadurch werden jedoch auch Dateien auf anderen Dateisystemen gefunden, die zufällig dieselbe Inode-Nummer haben.  
* Wenn foo ein Verzeichnis ist, verwenden Sie ln -di, in einer Zeile:  
<syntaxhighlight lang="bash" highlight="1" line copy>
find . -follow -inum $(ls -di foo.txt |cut -d" " -f1)
</syntaxhighlight>


To find a specific symlink, just <tt>grep</tt>
Diese Antwort ist falsch
symlinks -rv . | grep foo.txt*
* Ein symbolischer Link hat nicht dieselbe Inode wie sein Ziel. Dies funktioniert nur für eine Datei in einem Ordner mit symbolischem Link. Aber danach wurde nicht gefragt.  


Never heard of symlinks before (repo). 'A useful utility for maintainers of FTP sites, CDROMs, and Linux software distributions. It scans directories for symbolic links and lists them on stdout, often revealing flaws in the filesystem tree.' Great little ancient tool by ancient kernel hacker Mark Lord, the 'original developer and maintainer of the IDE Performance Package for linux, the Linux IDE Driver subsystem, hdparm', now maintained by J. Brandt Buckley.
== symlinks utility ==
Das [[symlinks]]-Dienstprogramm aknn auch bei der Suche nach defekten symbolischen Links nützlich sein.  


Works great and is fast. Note, however, that you'll need to do a search in each discrete partition of interest (as <tt>symlinks</tt> does not reliably (AFAIK) search across what is calls "different filesystems"). Also, <tt>symlinks -rv . 2>/dev/null | grep foo.txt</tt> may result in "cleaner" output...
[[Kategorie:Softlink]]

Aktuelle Version vom 11. Mai 2025, 13:47 Uhr

Alle Links finden

Wenn Sie versuchen, Verknüpfungen zu einer bestimmten Datei namens foo.txt zu finden, dann ist dies der einzige gute Weg:

find -L / -samefile path/to/foo.txt

Wenn Sie hingegen nur nach Verknüpfungen zu einer beliebigen Datei suchen, die zufällig foo.txt heißt, dann ist etwas wie

find / -lname foo.txt

oder

find . -lname \*foo.txt

das Problem mit den ignorierten führenden Pfadnamenkomponenten

  • wunderbar gelöst. Vielen Dank an alle, die geantwortet haben.

Wie ich in einem gelöschten Kommentar angemerkt habe, können Sie -xtype l verwenden, um nur die Liste der Symlinks zu finden

  • Sie können eine Rekursion durchführen, da jede der Dateien, die auf foo.txt verweisen, selbst von einigen anderen Links referenziert werden kann ... z. B.: A->B->foo.txt, /tmp/C->B->foo.txt und weitere

Dies kann auch funktionieren, wenn Ihr Namensbestandteil ein übergeordnetes Verzeichnis ist, das im Link genannt wird, indem Sie

 find . -lname '*foo.dir*'

(entspricht z.&nbsp:B.&nbsp:file.txt -> ../foo.dir/file.txt)

Diese Antwort ist wirklich hilfreich, vielen Dank. Übrigens, wenn wir mehr Informationen über die Ergebnisse von "find" erhalten möchten, können wir die Ausgabe von "find" an "ls" übergeben

 find -L /usr -samefile /usr/share/pyshared/lsb_release.py 2>/dev/null | xargs ls -al

Ermitteln Sie die Inode-Nummer der Datei und suchen Sie dann nach allen Dateien mit derselben Inode-Nummer

ls -i foo.txt
41525360 foo.txt
 
find . -follow -inum 41525360

Alternativ können Sie die Option lname von find verwenden, aber dies funktioniert nicht, wenn Sie relative symbolische Links haben, z. B. a -> ../foo.txt

find . -lname /path/to/foo.txt*

Wenn Sie eine aktuelle Version von GNU find verwenden, können Sie auch die Option -samefile mit -L verwenden, um den gleichen Effekt zu erzielen, ohne selbst nach der Inode suchen zu müssen

  • Dadurch werden jedoch auch Dateien auf anderen Dateisystemen gefunden, die zufällig dieselbe Inode-Nummer haben.
  • Wenn foo ein Verzeichnis ist, verwenden Sie ln -di, in einer Zeile:
find . -follow -inum $(ls -di foo.txt |cut -d" " -f1)

Diese Antwort ist falsch

  • Ein symbolischer Link hat nicht dieselbe Inode wie sein Ziel. Dies funktioniert nur für eine Datei in einem Ordner mit symbolischem Link. Aber danach wurde nicht gefragt.

symlinks utility

Das symlinks-Dienstprogramm aknn auch bei der Suche nach defekten symbolischen Links nützlich sein.