You’ve now learned most of what you need to know to use Command Prompt effectively. This lesson will be relatively simple compared to the previous. You may have already figured out what’s on this page by playing around with Command Prompt on your own. To make efficient use of Command Prompt, you’ll want to know the difference between absolute and relative paths.
Up until now, we have been using relative file/folder paths. When you change your working directory to get to a file, you are using relative paths. Absolute paths are paths that reference a file/folder regardless of your working directory.
For example, if your working directory is
notepad.exeis a relative path to Notepad
C:\Windows\System32\notepad.exeis an absolute path to Notepad
In the above example, both methods reference the same file. But the benefit of absolute paths is that you don’t need to change your working directory. Therefore your working directory could be
C:\User\somename\Documents, and you could run Notepad by typing
C:\Windows\System32\notepad.exe without changing the working directory first.
If you need to browse and use commands like
DIR, then you obviously don’t need absolute paths. However if you know exactly where your file/folder is, then absolute paths will save you time. There is also necessary utility in absolute paths, which you will learn by the exercise below.
Copying Files to New Folders
Here is an example of when you would want to use absolute paths. Suppose you need to use the
COPY command to copy
archive.zip from the folder
C:\User\Administrator\Documents to a flash drive assigned as
F:, and you want it in your
F:\backups folder on the flash drive. There are three straightforward ways to do this:
- Change your working directory to
copy archive.zip F:\backups\archive.zip
- Change your working directory to
copy C:\User\Administrator\Documents\archive.zip archive.zip
- Don’t change your working directory at all
copy C:\User\Administrator\Documents\archive.zip F:\backups\archive.zip
Method 1 uses a relative path for the file source, and absolute for the file destination.
Method 2 uses an absolute path for the file source, and relative for the file destination.
Method 3 uses absolute paths for both the file source and destination, because the working directory wasn’t changed.
Which method you use doesn’t matter. What’s important is getting a feel for the different ways you can use Command Prompt to complete your objectives as quickly, intuitively, and comfortably as possible.
The most useful keyboard shortcut for typing paths quickly is the tab key. If you haven’t already, try pressing the tab key multiple times at a blank prompt. Command Prompt will cycle through the file/folder names in your current working directory. You can also press shift+tab to cycle the opposite direction.
This works while you’re in the middle of writing a name too. Try typing half of a file name and then pressing tab to autocomplete the name.
Tab is also helpful when typing long absolute paths. For example, instead of typing the full line
cd "C:\Program Files\Internet Explorer", try just typing (all on one line):
cd C:\ProTAB, to get
cd "C:\Program Files"
\InteTAB, to get
cd "C:\Program Files\Internet Explorer"
When you want to re-type an old command, try using the up/down arrow keys to cycle through your current Command Prompt window history.
When you want to edit a command before pressing enter, try using the left/right arrow keys instead of pressing backspace a retyping everything.