I struggle to find a working find
command, I hope someone has an idea. Imagine the following structure, where path and path{0..1} exist and they are each mounted from a network storage device:
dir: /path/userA
link: /path/userB -> /path2/userB
dir: /path1/userA
dir: /path2/userB
My expected result is:
/path/userA
/path1/userA
/path2/userB
The find
command should look something like this:
find /path /path{0..9} -maxdepth 1 -type d -name userA -o -name userB
Unfortunately no matter how I tweak and twist the command, either less directories than the expected are shown or still all four... find seems to always follow the symlinks.
I've tried -P
, -H
, -L
options, tried "! -type l
" and various combinations, tried -exec addidtions like "-exec test -d {} \; -print
", none of them giving the expected result.
Interestingly, if I try to find only the symlink, find still follows it and print the referenced directory:
find /path /path{0..9} -maxdepth 1 -type l -name userA -o -name userB
/path/userB
/path2/userB
Thank you for your help!
-name userA -o -name userB
to\( -name userA -o -name userB \)
. – Kamil Maciorowski Feb 02 '24 at 12:56while IFS= read -r pathtotest; do cd -P thispath && pwd >> /path/to/the_list; done < /path/to/list_of_path_to_test ; sort /path/to/the_list | uniq
# cd -P will print the "canonical" path not the symlink-based one – Olivier Dulac Feb 02 '24 at 13:38