Difference between cd and function chdir

What is the difference between the cd shell command and the Perl function chdir? Please can you explain with an example?

2 Answers

The cd command changes the current directory of a shell process; the Perl chdir function changes the current directory of a Perl process. They're exactly the same thing, just spelled differently.

4

Essentially both of them do the same thing, but chdir is a POSIX system call while cd is a normal function used in a program which in this case is the shell.

In practice, chdir is called by cd to make the change in directory since the program does not have kernel privileges to do it by itself.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like