I don't understand why this two commands don't provide the same result (the differrence is only relative vs. absolute path), can somebody explain it?

annika /srv/www/pages/com.example.www/www/povruc # find /srv/www/pages/com.example.www/www | xargs grep "datepicker()" 2>/dev/null 
/srv/www/pages/com.example.www/www/povruc/Application/Libraries/3rdParty/zebra/includes/Date.php:    function disable_zebra_datepicker() {
/srv/www/pages/com.example.www/www/js/functions.js:       $(".datepicker").datepicker();


annika /srv/www/pages/com.example.www/www/povruc # find ../ | xargs grep "datepicker()" 2>/dev/null 
../povruc/Application/Libraries/3rdParty/zebra/includes/Date.php:    function disable_zebra_datepicker() {

In the second case the second match is not found

UPDATE - proved that there are no symlinks in the path:

annika /srv/www/pages/com.example.www/www/povruc # namei -ml $(readlink -f $PWD)
f: /srv/www/pages/com.example.www/www/povruc
drwxr-xr-x root       root /
drwxr-xr-x root       root srv
drwxr-xr-x root       root www
drwxr-xr-x root       root pages
drwxrwx--- Wexampl001 root com.example.www
drwxrwx--- Wexampl001 root www
drwxrwx--- Wexampl001 root povruc
  • 2
    directory you are in right now is likely a symlink; so ../ from where you are seemingly at will not go to dir below; rather dir below of readlink -f $PWD – Hrvoje Špoljar Nov 19 '14 at 10:05
  • btw, find | xargs is dangerous stuff, like really really dangerous, how dangerous it depends on what xargs is invoking, rather use find -print0 | xargs -0 . Hint, without -print0 -0 check what happens with files that have space in their name. – Hrvoje Špoljar Nov 19 '14 at 10:08

In essence this is the problem; directory from which you are doing the find is symlink; so relative move .. is not moving you to where you would expect; rather to .. of $(readlink -f $PWD)

moo:~$ mkdir foo bar
moo:~$ cd bar/
moo:~/bar$ ln -s ../foo/
moo:~/bar$ touch w00t
moo:~/bar$ ls -1
moo:~/bar$ cd foo
moo:~/bar/foo$ ls -1 ../

cool utils to determine real path of some file

$ readlink -f some_name

or check with namei how some path is linked with e.g.

$ namei -ml /etc/passwd f: /etc/passwd drwxr-xr-x root root / drwxr-xr-x root root etc -rw-r--r-- root root passwd

Example above does not contain symlinks along the path but it there were any it would show you in detail what the true path of some file is without symlink insanity.

  • No, there are not any symlinks in the path annika /srv/www/pages/com.example.www/www/povruc # readlink -f $PWD /srv/www/pages/com.example.www/www/povruc – Kuba Petržílka Nov 22 '14 at 22:42
  • 1
    what about output of namei -ml $(readlink -f $PWD) can you please update question with that output – Hrvoje Špoljar Nov 22 '14 at 22:55
  • Ok, I've updated the question – Kuba Petržílka Nov 22 '14 at 23:24
  • strange :\ I'm wondering if running find ../ | grep 'js/functions.js' when you're in povruc directory finds that file at all – Hrvoje Špoljar Nov 22 '14 at 23:39
  • Yes, it finds this file. What more is wierd, that if I do just: find ../ | sort > find1 and find /srv/www/pages/com.example.www/www/ | sort > find2 and then diff find1 find2 it shows no difference – Kuba Petržílka Nov 23 '14 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.