tags:

views:

101

answers:

5

what is the difference between cd and chdir command. both commands execute the same function. If both have the same function , why do we need two commands ??

+1  A: 

Nothing is different. They're just renamed versions of the exact same thing. cd is just shortened. http://technet.microsoft.com/en-us/library/bb490875.aspx

Nowayz
+1  A: 

cd is for lazy people.

On a slightly more serious note, on Windows they're both in fact the exact same thing.

C:\>cd /?
Displays the name of or changes the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
BoltClock
+3  A: 

cd is the shell command, chdir is the system call that it uses. They're on different levels of the software stack.

Zack
I found this out when writing my first shell...there's no way I'd know otherwise.
rownage
A: 

I believe you have to type the full path for CD no matter what, and for CHDIR you can specify subfolders without typing the full path.

cmd

Example from instructables.com

rownage
Not anymore for recent versions of Windows.
BoltClock
Umm...no. I `cd` to subfolders and `..` all the time. There is no difference at all.
cHao
noted! just never tried cd to subfolders because i assumed it wouldn't work.
rownage
@cHao: it doesn't prove a thing if you read it carefully.
BoltClock
@BoltClock: yeah, missed it. I just saw a bunch of statements with no errors, and CD and CHDIR all mixed in together, and figured someone who's trying to provide evidence would show an error message for statements that they claim don't work.
cHao
+3  A: 

In C programming:

In C programs, and other programming languages too, chdir() is the function used to change the current directory.

For Windows:
cd and chdir are both commands in the Windows command line that does the exact same thing, and cd is really just an alias for chdir.

For Unix::
cd is the shell command to change directories in Unix systems, while chdir() is - as noted above - only available as a function for C programs. chdir might work on some Unix systems as a shell command too, but it does not work on my Linux machine, though.

Frxstrem
I have the impression that `chdir` is available as a synonym for `cd` in `csh` and its derivatives, but I haven't used them in a very long time.
Zack