Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between cd and function chdir

Tags:

cd

perl

chdir

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

like image 364
iDev Avatar asked Aug 21 '12 00:08

iDev


People also ask

Are cd and chdir the same?

The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.

How do you use the chdir function?

chdir changes the current working directory of the calling process to the directory specified in path. Syntax: int chdir(const char *path); Parameter: Here, the path is the Directory path which the user want to make the current working directory.

What does cd mean in Linux?

cd command in linux known as change directory command. It is used to change current working directory. Syntax: $ cd [directory] To move inside a subdirectory : to move inside a subdirectory in linux we use $ cd [directory_name]

What does chdir return in C?

If successful, chdir() changes the working directory and returns 0. If unsuccessful, chdir() does not change the working directory, returns -1, and sets errno to one of the following values: Error Code.


2 Answers

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.

like image 52
Itamar Katz Avatar answered Oct 16 '22 14:10

Itamar Katz


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.

like image 37
Alan Curry Avatar answered Oct 16 '22 15:10

Alan Curry