Every one knows that find is an indispensable tool when you are working on Unix. But how many of you know about the -follow flag?
I was using it for years and till yesterday i haven’t come across an issue with the command.
Yesterday evening i was trying to locate an *.so file and noticed this interesting behaviour.
bash-3.00# pwd
/apps/jsws/webservers/https-ws.advisorchannel.com-444/components/fmr-plugins
bash-3.00# find ./ -name ‘*.so’ | wc -l
78
bash-3.00# cd ..
bash-3.00# find ./ -name ‘*.so’ | wc -l
0
When i do a find from one location, it says.. there are 78 files. When i just move back and run the find command again… it gives zero. Strange…!!! rite?
It took some time for me to figure out why this strange behavior was occurring.
I was about to send out an email telling that ‘.so’ files are missing.. then i noticed this,
bash-3.00# ls -l
total 2
lrwxrwxrwx 1 httpdadm httpdadm 26 Jul 8 10:01 fmr-plugins -> /apps/fmr-plugins/TKP15S02
lrwxrwxrwx 1 httpdadm httpdadm 31 Jul 8 10:01 jsws -> /apps/jsws/httpd/JSWS-7.0.1_S15
Ok, so that is the reason. Two of the sub directories under “components” are symlinks.
Find command, by default, does not recursively traverse symlinks. You need to add -follow flag.
bash-3.00#find ./ -name ‘*.so’ -follow | wc -l
273