One of the harshest realities facing many beginning IT professionals is that of haven’t been brought up in a “Windows-only” world. That is, the IT professional has never been exposed to having to work and accomplish tasks from a command line, but rather has used a graphical user interface (GUI) for everything. That is fine most of the time, but there are two times when relying on the GUI isn’t a good idea (or possible).
The first scenario where relying on the GUI is a bad idea is when you are doing telephone tech support and trying to walk a customer/user through a file system operation such as renaming or copying a file. Having been in this scenario myself in my telephone tech support days, I can attest to how difficult it is to perform tasks through the GUI when you are having to explain it to a user or customer on the other end who is unfamiliar with what you are trying to do, and you are unable to physically see what they are doing. In this case the command line makes the most sense, since they type in exactly what you tell them and there is less chance for error.
The second scenario is of course when Windows becomes corrupted and you can’t boot into the GUI. This is very common, and as a tech support person you are often called upon to save data or recover an existing installation without simply wiping out the hard drive and starting over. Because of this, being able to navigate the command line and manipulate the file system is an essential skill to have.
The principles of the command line are the same whether you are working in Windows (with its DOS underlying layer) or *nix (Unix/Linux). The syntax is different in some cases, as is the name of the commands used. Since the principles are the same, however, we will show you how to perform the functions under each OS. To begin with, here’s a table for reference that illustrates the relevant commands in each operating system as well as a description of their function.
|
Windows/DOS command |
Unix/Linux command |
Description |
|
dir |
ls |
display/list a directory listing |
|
copy |
cp |
copy file(s) |
|
move |
mv |
move file(s) |
|
ren |
mv |
rename a file/folder |
|
|
rm |
delete/remove file(s) |
|
rd/rmdir |
rmdir |
delete/remove a directory |
|
md/mkdir |
mkdir |
create a directory |
|
format |
mkfs |
format/create a file system |
|
fdisk |
fdisk |
partition a hard disk |
|
chkdsk/scandisk |
fsck |
check file system for errors |
|
chkdsk |
df |
view file system info |
The above certainly isn’t an exhaustive list of commands available, but rather an overview of some of the most commonly used commands for manipulating the file system.
One of the most important differences to note is that many of the commands used by both types of operating systems can involve the use of switches, which further delineate the task at hand. For example, if you wanted to format a partition in Windows you could simply type:
format d:
The above would prompt you to confirm you wanted to perform the task (since it is destructive in nature), and perform a standard format, prompting you for a volume label at the end. Alternatively, you could apply switches to supply additional information that affects the behavior of the task. With Windows NT-based operating systems you can even choose the type of file system (NTFS, FAT) that you wanted to use. An example of a more advanced command using switches would be:
format d: /fs:ntfs /v:data /y
The above would format the d: partition with the NTFS file system, apply the volume label data to the partition, and not prompt you to confirm the task. In *nix, the command mkfs (i.e. “make file system”) is used rather than format. It also can be modified with switches to affect its behavior. To format a partition called /dev/hda2 (partitions aren’t identified as letters in *nix as they are in DOS/Windows) with the FAT file system you would type:
mkfs -t msdos /dev/hda2
As you can see from the preceding examples, in the Windows world we use the / symbol from the command line to identify a switch, and a - in the *nix world.
As we’ve said, a common scenario for a desktop support person would be to have to work on a system that couldn’t boot into the GUI, but that still had a partition containing data to be saved. Windows 9x offers a boot disk creation utility through the Add/Remove Programs applet that gives you the ability to boot from diskette and have access to many of the common file system commands. With Linux you can also use the rawwrite utility with distributions such as Red Hat and Mandrake to create a boot disk. It is important to note that depending on the file system you are trying to access you may need different types of boot disks and possibly third party utilities.
Assuming you are able to boot to a command prompt and have access to the partition you are trying to read, you can first take a look around by typing dir or ls, depending on which operating system you are working in. As with format, there are switches for both dir and ls that affect how the directories and files are displayed. With Windows, you can almost always specify the /? switch to get usage info for the command. Some *nix commands will provide usage info if you don’t give enough info for the command to run, but more often than not you’ll have to view the man page (“manual”) for the command by typing man (command name).
Once you have displayed the contents of the partition and determined what you need, you can use further commands such as copy or cp to copy files to another partition or a floppy drive. You can also specify multiple files by using the wildcard symbol (*) in each operating system, which means everything. For example, to copy all Word docs from a directory named docs to the A: drive from a DOS/Windows command line you would type:
copy c:\docs\*.doc a:\
The same command in Linux would be:
cp /home/Will/docs/*.doc /dev/fd0
The above would copy all docs from the docs directory within my home directory to the floppy drive.
You could alternatively move the files, or use similar techniques to replace a corrupt file that might be causing the system failure in the first place from a good backup or the installation disks.
Before we close there is one very important note to make. Many people who are used to Windows and GUI based operating systems have grown accustomed to “trash can” or “recycle bin” functionality. Those are utilities designed to provide the ability to recover files or folders/directories that have been accidentally deleted. When you are working from the command line, you do not have that functionality. If you delete a file or directory, it is for all intents and purposes gone (unless you use third party utilities or services to recover the data at a low level). So, be careful when you are manipulating the file system in this manner.
The ability to effectively use the command line should be a part of every IT professional’s skill set. Regardless of whether you are using a Microsoft operating system or a Unix/Linux-based operating system, the principles are the same. Remember to view the help files for the commands as you are learning them, because many of them have switches that can be optionally used to change the default behavior of the command. Being able to work from the command line has allowed me to bail out many customers who thought they had lost important data, and by learning the commands and their usage at some point you’ll have the opportunity to be a “hero” to a user or customer as well.
Questions or Comments?
Will can be reached at WWillis@Transcender.com