2

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!

dreamcocoa
  • 23
  • 2

1 Answers1

2

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).