URL: <https://savannah.gnu.org/bugs/?58458>
Summary: Using -L option and -samefile test will match both hard links and symbolic links, but the manual is incorrect Project: findutils Submitted by: comppreper Submitted on: Thu 28 May 2020 06:17:46 AM UTC Category: documentation Severity: 3 - Normal Item Group: None Status: None Privacy: Public Assigned to: None Originator Name: Originator Email: Open/Closed: Open Release: 4.7.0 Discussion Lock: Any Fixed Release: None _______________________________________________________ Details: The second paragraph under section 2.2.2 Hard Links <https://www.gnu.org/software/findutils/manual/html_mono/find.html#Hard-Links> states as follows: If the _‘-L’_ option is in effect, and _name_ is in fact a symbolic link, the symbolic link will be dereferenced. Hence you are searching for other links (hard or symbolic) to the file pointed to by _name_. If _‘-L’_ is in effect but _name_ is not itself a symbolic link, other symbolic links to the file _name_ will be matched. The above paragraph is not entirely correct and is likely to mislead the reader. If _name_ (ie the filename provided to the _-samefile_ test) refers to a file that has both hard links and symbolic links, then the _‘-L'_ option will cause both hard links and symbolic links to be matched, even if _name_ does not refer to a symbolic link. Therefore, it is not correct to suggest that only symbolic links will be matched. Unfortunately, when read in context, the last sentence of the above paragraph suggests that only symbolic links will be matched. In fact, to be clear, the _‘-L’_ option will always match both hard links and symbolic links irrespective of whether _name_ refers to a hard link or symbolic link. Of course, if a file has only one name (ie other names have not been hard-linked to the file), then the _‘-L’_ option will only ever find the file itself (if it is within the search scope) and other symbolic links (if any) within the search scope. For example: touch ./original-file.txt link ./original-file.txt hardlink.txt ln -s ./original-file.txt symlink-original.txt ln -s ./hardlink.txt symlink-hardlink.txt ln -s ./symlink-original.txt symlink-symlink.txt ln -P ./symlink-original.txt hardlink-symlink.txt find -L -samefile ./original-file.txt ./original-file.txt ./hardlink.txt ./symlink-original.txt ./symlink-hardlink.txt ./symlink-symlink.txt ./hardlink-symlink.txt find --version find (GNU findutils) 4.7.0 Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://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) In view of the above, I suggest changing the second paragraph under section 2.2.2 Hard Links <https://www.gnu.org/software/findutils/manual/html_mono/find.html#Hard-Links> to read as follows: If the _‘-L’_ option is in effect, then any symbolic link will be dereferenced (this is the case for both the file name and the _name_). Hence, you will be searching for both hard links and symbolic links to the file pointed to by _name_. _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?58458> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/