I’ll admit, this one does seem a little basic. However, it’s something that’s often struck me as odd, yet I’d never bothered to look into further until this week, when my curiosity got the better of me.
In Windows, as in Linux, it’s really easy to change directories when in a command prompt. Say you’re in C:\Users\User, and you want to change to C:\Users\User\Desktop, you would put in the following:
cd Desktop
If you wanted to switch to C:Windows\System32, you would put in the following:
cd C:\Windows\System32
Simple, right? So, if you store files on another drive (as I always do, because it makes backups and sharing much easier for me), and you want to switch to, say, D:\Websites\Website\, you would put in the following:
cd D:\Websites\Website
The trouble is, it doesn’t work. I would always have to do the following:
D:\ cd Websites\Website
Until now, I’d never been bothered enough to look at what i need to do to make it work. It turns out, when switching drive letters as well as directories, you need to use a switch, /D. so, to do it in one line, you need the following:
cd /D D:\Websites\Website
To be honest, I can’t really see any reason why you would need a switch, since nothing happens at all if you don’t use it, but I’m sure someone, somewhere, will know why it’s implemented like that. Although come to think of it, I’ve never really understood why Windows still uses drive letters, as the Linux model of folders relative to root seems much more logical to me!
There are a number of different historical reasons for this. Unix was originally developed for systems that didn’t have removable storage (mostly because it didn’t really exist in the same way). Now – it’s way of mounting drives to a logical file structure is much more intuitive, but has also had it’s share of problems, particularly in the modern era of floppy disks, then CDs, and now USB storage. DOS was originally designed for systems that would have at least 1 removable drive, and so drive letters was it’s choice.
Interestingly (for certain values of interesting) the way the cd command works in Windows is actually pretty *nix-like. It does one thing (change directories) well. But what you want is 2 things – switch drive and change directory.
Thanks Ben, I figured someone like you might know more about why it is how it is, and I guess what you say about doing one thing and doing it well is a valid one, I just haven’t ever seen it as such, as I see everything connected to the computer as part of that structure, rather than individual components.
One thing I’ve always found challenging is remembering equivalent commands in Windows and Linux, and I do like how PowerShell solves this on Windows by accepting Linux commands, like “ls”, so I don’t have to remember it’s “dir” in Windows. Better still when I can set PowerShell as the default shell environment now.