For exercise - I removed execute permission for others from /bin/pwd:

$ chmod o-x /bin/pwd
$ ls -l /bin/pwd
-rwxr--r-- 1 root root 26568 Apr 28  2010 /bin/pwd

and as logged as matt I cannot execute /bin/pwd as expected:

$ /bin/pwd
$ -bash: /bin/pwd: Permission denied

but sudden it can be executed if not absolute:

$ pwd
/home/matt

Why? Thank you!

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

pwd is a shell built-in. You can see that with

$ type pwd
pwd is a shell builtin

pwd is a built-in in most shells. One reason for that is that it's a very simple command that's used fairly frequently (and running a built-in is faster than spawning an external process). Another reason is that it allows the shell to track symbolic links, so that cd /foo/bar; pwd shows /foo/bar even if bar is a symbolic to /wibble (in bash and many other shells, you can use pwd -P to show /foo/bar and pwd -L to show /wibble; the default is controlled by the -o physical option).

link|improve this answer
Thank you!!! I didn't know that pwd is a built-in! Wow! – dreamcocoa Sep 8 '11 at 21:46
feedback

Your Answer

 
or
required, but never shown

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