Difference Between Cd and Function Chdir

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

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

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.