문제

i can find all link in dir by command:

find . -type l

But i need link which only refer to files outside of PWD. Can anybody say how to do it? Thanks.

도움이 되었습니까?

해결책

I would do something like:

find . -type l -exec readlink -f '{}' \; | grep -v "^`readlink -f ${PWD}`"

readlink -f gives you the canonical path of a file, so the first command gives you the path of links and the grep command excludes files beginning with the current path.

If you want to remember which links pointed to those paths, here's a way to do it:

find . -type l -exec sh -c 'echo $(readlink -f "{}") "<-- {}"' \; \
  | grep -v "^$(readlink -f ${PWD})"

the -exec switch is more complicated since you have to display both the linked path and the path of the symlink.

다른 팁

Ich would do something like:

for link in `find . -type l`; do X=$(dirname `readlink $link`); if [ $X != '.' ]; then echo $link; fi ; done
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top