Following http://superuser.com/questions/1780479 and http://superuser.com/questions/1777606, we issue the following script to compare times of the same–full-path symlinks under directories $1 and $2:
#!/bin/bash
cd $1
find . -type l -exec bash -c "if [[ -h \"{}\" && -h \"$2/{}\" ]]; then if (test $(readlink \"{}\") = $(readlink \"$2/{}\")) then if (find \"$2/{}\" -prune -newer \"{}\" -printf 'a\n' | grep -q a) then echo \"{} is older than $2/{}\"; else if (find \"{}\" -prune -newer \"$2/{}\" -printf 'a\n' | grep -q a) then echo \"$2/{} is older than {}\"; fi; fi; fi; fi" \;
The usage is compare_times.sh directory_1 directory_2 (where compare_times.sh
is the name of the script). We use it as demonstrated in the following example:
user@machine:/tmp/D1$ ls -lt --full-time /tmp/linked_file /tmp/D*
-rw-r--r-- 1 user user 0 2023-04-25 00:12:09.289942358 +0200 /tmp/linked_file
/tmp/D2:
total 0
lrwxrwxrwx 1 user user 14 2023-04-25 00:07:00.265830604 +0200 lnk -> ../linked_file
/tmp/D1:
total 0
lrwxrwxrwx 1 user user 14 2023-04-25 00:06:40.922078186 +0200 lnk -> ../linked_file
user@machine:/tmp/D1$ compare_times.sh . ../D2
./lnk is older than ../D2/./lnk
user@machine:/tmp/D1$
As you see, find
calls bash
, which itself calls find
. (Probably, this might be written more elegantly, but this is not the point now.) Are there any issues with calling find
from under find
this way?
The man page of the find
command doesn't say whether find
is reenterant or not. If find
is not reentrant, we could hypothetically silently miss some output, i.e., some symlinks that have the same name and the same position inside the two directories and that point to equal filenames but that have different timestamps.
find
is just a utility, and if it calls itself, it just calls itself. I have much much more to say about the obvious other issues in your code though, so if you update your question with whatever it is that you are having a problem with, we may be able to help you sort it out. – Kusalananda Apr 24 '23 at 15:24find
can be called fromfind
with no issues. However, your code has code injection vulnerabilities and quoting issues that may cause it to fail or behave in unexpected ways. Since you explicitly discourage us from helping you with your code, I will say nothing further about that. – Kusalananda Apr 24 '23 at 15:31$1/
and$2/
. – Apr 24 '23 at 22:27