Windows Shell Tutorial (2024)

Cay S. Horstmann

Windows Shell Tutorial (1)
Windows ShellTutorial by Cay Horstmann is licensed under a Creative CommonsAttribution-Noncommercial-Share Alike 3.0 United States License.

Operating Systems, User Interfaces, and Shells

The operating system manages theresources of a computer, such as its internal memory, the disk drives,keyboard, monitor screen, mouse, printers, and network connections. People whouse a computer to browse the web or play games have minimal contact with theoperating system. Most of their time is spent with application programs.

These users tend to use the operating system only to fix problems, forexample with a failed internet connection. The most recent versions of popularoperating systems (such as Windows XP) have become very much oriented towardsthe consumer, hiding all but the most basic tasks from the casual user.

Computer programmers have more advanced needs than people who use thecomputer as a tool. Programmers need to compile and launch programs andautomate recurring tasks. This tutorial is written for programmers who arealready familiar with the basics of using a computer.

If you have prior experience using a computer for playing games or writingreports and are now learning to program, you will need to learn more about youroperating system. Some students are reluctant to embark on this effort, eitherbecause they feel that they already know how to use their computer, or becausethey already have their hands full learning about programming. However, that isa short-sighted attitude. Without knowing the operating system, many commonprogramming tasks seem tedious or even impossible.

Operating systems come with two different kinds of user interface:

  • a graphical user interface or GUI
  • a command line interface, also called a shell

Most computer users are familiar with the graphical user interface or GUI.Most GUI environments display a desktop that is populated with windows, icons and menus. You use apointer (directed by a mouse or trackball) toselect items on the desktop. These interfaces are sometimes called WIMP interfaces, after the first letters ofthe words window, icon, menu, and pointer. Here is a screen capture ofa typical WIMP interface:


Windows Shell Tutorial (2)

The other user interface is a commandshell. A command shell is simply a window without any graphicaldecorations. You type commands, using the keyboard, and you see the results ofthe commands displayed as text. There are no icons, and you can use the mouseonly in limited circ*mstances. Here is a typical command shell:

Windows Shell Tutorial (3)

A command shell is not a good user interface for casual users. However,experienced users find that the command shell is indispensible for many tasks.

Look at it this way. If you just want to snap vacation photos, you'll use a"point and shoot" camera. It requires no training and takes decent pictures.

Windows Shell Tutorial (4)

But if you want your photos to be published in a magazine, you will need aprofessional camera. You will need to spend time learning rather technicalconcepts such as f-stops andshutter speeds.

Windows Shell Tutorial (5)

We don't want to leave you with the impression that the command shell is thebest tool for every job. Sometimes, you are better off using the GUI,particularly if you spend some effort learning how to use it efficiently. Justlike a professional photographer chooses the best instrument for the job, youwill need to learn when to use the GUI and when to use the command shell.

In this tutorial, you will learn some tricks that make the GUI faster andmore efficient, and you will learn the basics of the command shell.

Keyboard Shortcuts

Running a program

After you log on to your computer, you see a desktop, which may ormay not contain some icons (small pictures representing programs,services, or resources). At the bottom left of the screen is the Startbutton. Across the bottom, is the task bar which contains buttons forall currently running programs. If you are reading this document in a webbrowser (and not from a printout), then there should be a button correspondingto the browser program. At the bottom right of the screen is a clock, possiblytogether with somesmaller icons.

You probably know how to launch programs by clicking on the start button oron desktop icons. We will now introduce another method.

Type the keyboard shortcut Ctrl+Esc. That is, hold down the Ctrl key, and, without lifting your fingeroff it, hold down the Esc key. Then letgo of both keys (in either order). This keyboard shortcut simulates a click onthe Start button.

Why use a keyboard shortcut? It is much faster to hit Ctrl+Esc than it is to

  1. grab the mouse
  2. move the mouse to the lower left corner of the screen
  3. click the mouse button

For a programmer, the first step ("grab the mouse") is the most painful.Programmers need to type a lot of code and therefore have their hands on thekeyboard most of the time. In this regard, programmers are very different fromcasual computer users who have a hand on the mouse much of the time.

You will see a popup menu, containing icons and names. The exactlayout of the menu depends on the version of Windows and on the customizationof the start menu. Here is one example. Your dialog may well be quitedifferent.

Windows Shell Tutorial (6)
Windows Shell Tutorial (7) NOTE: If you use Windows XP, it is a good idea to switch the start menu to "Classic" mode. The setting is inside the Taskbar and Start Menu control panel. (While you are at it, you should switch the control panel view to "Classic" mode as well.)

In any menu, you can quickly select items that have underlined letters intheir names. For example, typing R isthe same as selecting theRun item. Typing H is the same as selecting the Help item.

Windows Shell Tutorial (8) NOTE: If you use Windows XP, the underlined letters may not show up until you hit the Alt button. This unfortunate behavior can be corrected in the Display Properties control panel dialog. Select the Appearance tab and click on the Effects button...

Hit the R key now. You will get adialog. Type the word notepad.

In most dialog boxes, hitting the Enter key is the same as clicking the Ok button. Typing Esc dismisses the dialog, just as if you hadclicked the Cancel button.

Hit the Enter key now. The Notepadprogram launches.

Exercise 1
Which keystrokes are required to launch the Notepad program without touching the mouse?

Exercise 2
What is the advantage of using the Run dialog to launch the Notepad program? Hint: Locate the Notepad program in the start menu tree. In which submenu did you find it? How long did it take you to find it? Will it be in the same position on your friend's computer?

Toggling between programs

The next step of this tutorial assumes that you currently have a web browserrunning. If you are reading these instructions from a printout, go ahead andstart a browser. Close any windows except for the browser and the notepadwindow.

You now have two windows on your desktop: the browser and the Notepadprogram. This is an extremely common situation for a programmer. You will oftenwrite a program in one window while consulting documentation in another window.It is essential that you can switch quickly between the windows, even if somewindows hide others.

The fastest way of switching between windows is the Alt+Tab keyboard shortcut. Press Alt+Tab now. You will get a dialog that listsall windows. Release both keys. You instantly switch to the next window.

Start the calc program (Ctrl+Esc R calcEnter). You should now have three programs running. Hit Alt+Tab again, but this time keep the Alt key depressed and repeatedly hit theTab key. You toggle through the programicons. Let go of both keys when you have reached the browser program.

Exercise 3
Run three programs, for example, a browser, the notepad, and the calc program. Switch to the browser program if it is not currently active (either with the mouse or with Alt+Tab). Hit Alt+Tab and let go immediately. Which program is selected now? Hit Alt+Tab again and let go immediately. Which program is selected now? Why is the result surprising? Why is it useful?

Managing windows

When the time has come to close an unwanted window, you can close it byclicking on the X icon in the top right corner, or you can use a keyboardshortcut. There are actually two shortcuts. The combination Alt+F4 closes the active window, but evenkeyboard enthusiasts will find it hard to remember.

More useful is the Alt+Spaceshortcut. It brings up the windowmenu:

Windows Shell Tutorial (9)

Select C to close the window.

The window menu has a number of other useful options:

  • Maximize: Make the window fill the entire desktop
  • Restore: Restore the window to its original size, before maximizing
  • Minimize: Temporarily remove the window from the screen (to reduce clutter)
You can get a minimized window back onto the desktop by cycling to it withAlt+Tab.
Exercise 4
Suppose you want to see as much information as possible in your browser window. What keystrokes do you use to maximize the browser window?

Cut, Copy and Paste

One of the most common operations for text manipulation is cut-and-paste:transferring information from one place to another. Because these operationsare so common, there are special keyboard shortcuts for them.

Switch to the notepad window.

Pull down the Edit menu by typing Alt+E. Note the underlined E in the menu name. You pull down amenu by typing the Alt key and theunderlined letter.


Windows Shell Tutorial (10)

The Edit menu has commands for theCut, Copy, and Paste operations. Thus, a perfectlyreasonable keyboard shortcut for copying text would be Alt+E C. However, because the copy operationis so common, there is an accelerator,Ctrl+C, that lets you access theoperation with a single key combination. You can see the accelerator listed inthe menu. Similarly, there are accelerators for cut (Ctrl-X) and paste (Ctrl-V). These key combinations are perhapsnot as easy to remember. You may find it helpful to visualize the X as crossingout text, and the V as an insert mark for adding text:


Windows Shell Tutorial (11)

Also note that the letters X, C, V are located next to each other,conveniently close to the Ctrl key (atleast, on the standard English QWERTY keyboard layout).


Exercise 5
Now switch to the browser window. If it doesn't currently show a document, then visit your favorite web site. Use the mouse to select a phrase of your choice. Your task is to copy the selected text to the Notepad program, without further use of the mouse. What keystrokes to you use?

Windows Shell Tutorial (12) NOTE: Many programs also support alternate keyboard shortcuts: Shift+Delete for cut, Ctrl-Insert for copy, and Shift-Insert for paste. However, these shortcuts are not as universally supported as Ctrl-X, Ctrl-C, Ctrl-V.

Moving the Cursor and Selecting Text

You can move the cursor by clicking on the desired location, and you should dothat if the desired location is far from the current location. However, if youjust need to move the cursor by a small amount, it is often faster to use thefollowing keys:
  • The arrow keys Left, Right, Up, Down move the cursor one position
  • Ctrl+Left, Ctrl+Right move the cursor one word to the left or right
  • Home, End (above the arrow keys) move the cursor to the beginning or end of the line
  • PageUp, PageDown (above the arrow keys) scroll the page up or down. This is often faster than using the scroll bars.
Windows Shell Tutorial (13)
You know that you can select text with the mouse, by clicking on the beginningof the text and dragging the mouse to the end. Indeed, that is often thefastest method. However, if you need to select a short amount of text and yourfingers are on the keyboard, then it is useful to know a shortcut.

Hold down the Shift key and move thearrow keys. You will see that a portion of text is selected. You can also usekeys such as Home and End to extend the selection to the beginningand the end of a line.

Exercise 6
Switch to the notepad. It should still contain some text from a preceding exercise. If not, paste or type a couple of lines. Now highlight the entire line containing the cursor, using as few keystrokes as possible. What keystrokes to you use?

Navigating in Dialogs

It is handy to know how to move quickly through the fields of a dialog boxwithout using the mouse.

In any dialog box, you can use the Tab key to cycle through all ofthe fields and buttons. Consider for example the following dialog from theNotepad program. (The menu option is Edit -> Replace.)

Windows Shell Tutorial (14)
Windows Shell Tutorial (15) NOTE: This is the dialog from Windows XP. If you use an older version of Windows, use the Search -> Find dialog instead. It isn't as interesting, but you can still use it to try out the Tab key behavior.

Type the Find what entry, then hit theTab key to quickly get to the Replace with field. The Tab key is particularly handy for dialogsthat have many text fields.

When you use the Tab key to cyclethrough the dialog box, observe how the focus shifts from one field to the next. Atext field with focus has a blinking cursor. A button with focus has a dottedrectangle around the button label. The focus tells you which part of the dialogbox receives keyboard input. For example, if a button or checkbox has focus,then hitting the Space bar is the sameas clicking it with the mouse.

If an item name has an underlined letter (such as Match case), then you can typeAlt together with the underlined letterto reach it quickly. For example, Alt+Cis the same as clicking the Match case checkbox.

Finally, most dialogs respond to two special keys. Typing Esc dismisses the dialog, just as if you hadclicked the Cancel button. Typing Enter is the same as clicking the Ok button.

Exercise 7
Open up the Find dialog in Notepad. What keystrokes do you need to find the next occurrence of Hello, with Match case checked? Keystrokes only, no mouse!

You know know the most common keyboard shortcuts. After a short amount ofpractice, you will probably agree that the keyboard is mightier than the mousefor many routine tasks.

The File System

Disk drives

Disk drives for computers come in two main types, removable (floppy, CD ROM)and non removable (hard). Whether hard or floppy, a computer disk driveessentially contains a round, flat, object, and it reads its surface with amagnetic or optical head.

In addition to the disk drives that are physically present in a computer,there may be several mapped drives that are provided by the networkserver. These are not actual drives at all, but look to the operating system(and to you) as though they are.

The drives that hold the disks are named by a letter followed by a colon(:). The names a: (and perhaps b:) are the floppy drives.The names c: and d: are usually used to name hard disk drives inthat same computer. CD ROMS come next, labeled e: (or d:if there is only one hard disk). Higher letters like j:,k:, ... are mapped network drives.

Windows Shell Tutorial (16) NOTE: Sometimes, a single hard drive has multiple partitions. Even though there is only a single physical drive, it divided into several areas, each of which has its own drive letter (c:, d:, ...). If you set up your own computer, it is an excellent idea to set up two partitions, one for the operating system (c:) and one for your personal data (d:). That setup enables you to reinstall the operating system without interfering with your personal data. (Unfortunately, the Windows operating system is notorious for becoming unreliable over time, as more software is installed and programs and drivers interfere with each other. The best remedy is to periodically wipe the c: partition clean and reinstall Windows.)

Windows Shell Tutorial (17)
NOTE: In Linux/Unix/Mac OS X, there are no drive letters. Instead, CD ROM and floppy drives are accessed through paths such as /mnt/cdrom and /mnt/floppy.

There are many ways to find drives and view their contents using Windows.The program we will use is called Windows Explorer. (This is not the same program as Internet Explorer, Microsoft's web browser.The Windows Explorer program explores the file system, not the internet.)

To start the Explorer program, open the Run dialog (Ctrl+Esc, R) and type explorer followed by the Enter key.

Windows Shell Tutorial (18)

The look of the Explorer has changed greatly with different versions ofWindows, and it can also be configured in many ways. Don't worry if yourExplorer window looks quite different from this screen shot.


Exercise 8
List all available drives with their names and drive letters. (You may need to open the My Computer item.)

Each drive contains files and directories (also called folders). In the Explorer program, click on adrive to see the files and folders. The files are depicted with an icon thatlooks like a file folder. Files have different icons that depend on their type.

Windows Shell Tutorial (19)
Exercise 9
List all files and directories that are inside your c: drive. (Don't look inside the directories.)

Directory Trees

A typical hard disk holds thousands of files. It is therefore essential toorganize your files on the disk. As you accumulate files on a disk, you storethem in groups by creating directories.Directories are also called file folders. Generally, programmers preferthe term "directory", and we will use that term in this tutorial.

Each directory can contain any number of files and other directories calledsubdirectories. This arrangement is known as a hierarchical or treelike directorystructure.

To visualize the hierarchy of directories, it is best to look at the tree view to the left of the Explorerwindow. Note that each drive has a small box next to it with either a + or -sign in it. This indicates whether the next level of the directory hierarchy ishidden or expanded. Click on the + icon to expand a hidden level, on the - iconto hide an expanded level.

On each drive, the hierachy starts with the root directory. The nameof the root directory is simply the drive name followed by a backslash (such asc:\). The root directory contains files (such as c:\logfile.txt) anddirectories (such as c:\windows). The windows directory contains other files(such as c:\windows\notepad.exe) and directories (such as c:\windows\system).

The sequence of subdirectories from the root to a given file or directory iscalled the path. For example,c:\windows\system is the full path name of the system directory inside thewindows directory inside the c: drive.

Exercise 10
List an additional file and an additional directory in the c:\windows directory. List a file and a directory in the c:\windows\system32 directory. Give the full path names for the files and directories.

Exercise 11
Find the files explorer.exe and telnet.exe. Give the full path names. (Hint: You may find it easier to look for files if you select the list view rather than the icon view for directories. Choose the View -> List menu option.)

Exercise 12
Find a file whose full path names contains at least four directories.
Windows Shell Tutorial (20)
NOTE: In Linux/Unix/Mac OS X, directories are separated by forward slashes (/). For example, /usr/local/java/bin. That is the same convention as for web page addresses. Only Windows uses backslashes (\).

Making Directories

For this part of the tutorial, you need to find a directory into which youare allowed to place files and folders. On your own computer, you can simplyuse c:\, the root directory of the c: drive. If you work in a computer lab, youwill need to find out the name of the directory that was created for your use.


View your directory in the Explorer program. Select File -> New ->Folder (Alt+F W F). Thiscommand places a folder icon inside the directory and gives it the temporaryname New Folder. It also leaves the cursor in the name field, allowingyou to change it immediately. Hit Delete to erase the name, and give ita new name. A good choice for a name is your own name, contracted to a singleword without spaces (such as joe or jqsmith).


If you use your own computer, create this directory now. From now on, placeall files in this directory. If you use a computer in a lab and someone elsehas already given you a directory with your name (perhaps d:\jqsmith orc:\users\jqsmith), then you can skip this step.


We will refer to "your" directory as the c:\yourname directory in thistutorial, even though it will certainly be something else (unless, of course,your name is Yolanda O. Urname...)


Exercise 13
Create a subdirectory called tutorial inside the c:\yourname directory. (Substitute the actual directory that you created.) List all steps, starting with launching the Explorer program. (Close it first if it is currently running).

File and Directory Names

You can use letters, numbers, the underscore (_) and the hyphen (-)character in file names. Obviously, you can't use symbols such as : and \ infile names, or they would be confused with drive and directory separators.There are a few other special characters that you can use, but the detailsdepend on whether the drive is a local drive or a networked drive. It is bestto avoid file names with exotic symbols such as !@#$.


You can use spaces in file names, but programmers rarely do that, becausespaces in file names create problems when you use a command shell. Instead, use- or _ to separate words: myproject-ver0.01.java or letter_to_fifi.txt.


Both uppercase and lowercase letters are permitted in file and directorynames, but Windows will not distinguish between names that differ only in thecase of the letters.


Exercise 14
Create another subdirectory called TUTORIAL inside the c:\yourname directory. (Substitute the actual directory that you created.) What error message does Windows give you? What does it do after you click OK?

Files

Start the Notepad program: Ctrl+Esc Rnotepad Enter. Type a few words. Select File -> Save As from the menu. You willget the Windows file dialog.

Windows Shell Tutorial (21)

The dialog suggests a file name *.txt. However, you can't actually usethe * character in a filename.Also, the current directory is likely to be wrong. Fortunately, in mostversions of Windows, the useless default is also highlighted, so you canovertype it.

Simply type c:\yourname\. (Actually, type the name of your personaldirectory.) Type the letters s l o w l y and pay close attention to the entryfield. You will see that a small menu below the entry field is filled with thenames that match what you have typed at this point.

Windows Shell Tutorial (22)

This feature is a great time-saver. As soon as you see the name that matcheswhat you want to type, hit the Downarrow button to select it. Presenting all choices that match the typed lettersis called incremental search. Clearly,incremental search is a marvelous convenience because it minimizes the numberof keystrokes.

Exercise 15
What choices do you get after you type the letter c (or whatever the drive letter of your personal directory is)? What choices do you get after you type c:\ and the first letter of the directory name?
Windows Shell Tutorial (23) NOTE: Very old versions of Windows do not offer incremental search in the file dialog.

Save the file as c:\yourname\tutorial\sample.txt. Be sureto supply the extension .txt. That extension signifies that thefile is a text document.

Exercise 16
Close the Notepad program and locate the file that you just saved in the Explorer program. What icon does it have? What name is displayed for the file? What happens when you double-click on the file name?

Depending on the configuration of Windows, the extension .txt may not be displayed when you viewthe file in the Explorer program. By default, Windows hides the extensions,presumably because naive users are confused about file names such as letter to aunt tilly.txt.

Windows Shell Tutorial (24) NOTE: Hiding extensions is primarily helpful for virus writers. Many Windows users have eagerly double-clicked on icons labeled something like prettygirl.gif, only to launch a virus program whose real name was prettygirl.gif.exe.

As a programmer, you don't want the operating system to hide informationfrom you. Fire up the Explorer program and select Tools -> Folder Options and select theView tab.

Windows Shell Tutorial (25)

M

ake sure the check box next to "Hide file extensions for known filetypes" is unchecked. Click on it if it is checked. Then hit Enter orclick OK. Make sure to repeat this step onevery Windows computer that you use.

Windows uses the file extension to figure out what to do with the file whenyou double-click on it. Double-clicking on a .txt file brings up Notepad.Double-clicking on a program file (with extension .exe) executes the program.

You can find out which program corresponds to a particular extension. In theExplorer program, select the Tools ->Folder Options File Types tab.You get a list of all file types that are registered with Windows. You (or aprogram that you install) can modify these associations.

Exercise 17
Which program is associated with the extension .html? Which program is associated with the extension .gif?

Context Menus

Items such as file and directory icons in the Explorer display have context menus that contains commands directlyrelated to the item. This menu can be displayed by clicking on the object'sicon with the right mouse button.

Windows Shell Tutorial (26)

One of the most useful entries in the context menu of a file isRename. To rename a file, right-click on the file, select Renameand type the new file name.

Exercise 18
What are the commands listed in the context menu for the c: drive? What are the commands listed in the context menu for the c:\yourname\tutorial\sample.txt file?

Moving and Copying Files

Files and directories often need to be copied. There are two methods forcopying files with the Explorer program.

The most intuitive method is drag-and-drop: select a file with themouse, drag it to another directory, and drop it. If you hold down the Ctrl key while dragging the file, it iscopied, not moved.

With some manual dexterity, you can also drag a group of files. To selectmore than one file, depress the Ctrlbutton and click on all files in the group. For selecting multiple files withsimilar properties (such as the same extension, or similar modification dates),you may find it helpful to switch to a tabular view (menu option View -> Detail). Depress the Shift button and use the Up and Down arrow keys to select a contiguous set offiles.

The difficulty with drag-and-drop is that both the source and targetdirectory need to be on the desktop. You can overcome that problem by cuttingand pasting files. Select the files you want to move or copy. Then select Edit -> Cut (or simply Ctrl+X), move to the directory into which youwant to move the files, and select Edit ->Paste (Ctrl+V). To copy thefiles, use Edit -> Copy instead.


Exercise 19
Copy all files with extension .txt from the c:\yourname\tutorialdirectory into the c:\yourname directory. What sequence of keystrokes and mouse operations did you use? (Make sure to copy the files. Do not move them!)

Backing up your work

Computers are fairly reliable, but their parts do have a finite lifetime.Also, important files can sometimes be destroyed by careless computer users.You should make it a habit to back up all important files. Your instructor willlikely not accept "The computer ate my file!" as an excuse for late or missinghomework.

In ancient times, floppy disks were used to back up data. However, floppydisks are actually more fragile than hard disks. Also, the disk drivealignments of different computers can vary, sometimes so much so that itbecomes impossible to read a floppy disk that was written on another computer.It is best if you use floppy disks as a matter of last resort.

On your own computer, the most convenient backup method (as of 2003) is a CDburner. Windows XP has a rudimentary feature set for burning CDs. You caninsert a blank CD, drag files onto it, and burn the CD. However, some computermanufacturers preload software that offers a different interface to the CDburner, and older versions of Windows require a separate programs for CDburning. Since the details vary widely, we cannot review the process in thistutorial.

The best method for backing up your work in a computer lab is an onlineservice such as Yahoo Briefcase. Youcan save files on an external server and load them back either onto the samecomputer (in case you need to restore a lost or corrupted file), or ontoanother computer (in case you need to move your work between your lab and homecomputers).

Exercise 20
Back up the file c:\yourname\tutorial\sample.txt, either onto an online service or onto a floppy. Describe the steps that you took. Now delete the file and restore it from your backup. What steps did you take to restore the file?

The Command Shell

You have now learned how to navigate the Windows desktop effectively. The finalpart of this tutorial covers the command shell. You may wonder why you need tolearn another method for achieving the same tasks. There are three reaons:
  1. It is much faster to type certain commands than clicking and dragging with the mouse. For example, suppose you want to erase all text files in a folder. In a GUI, you select all text files and then drag them to a trash can icon. In a command shell, you type a few keystrokes such as
    del *.txt
  2. You can save the output of a command for later processing. For example, suppose you want to do something with all text files in a folder. You can save their names in another file with a command such as
    dir *.txt > names.dat
    Try doing that in a GUI. If you take a screen capture of a folder display, all you get is a bunch of pixels.
  3. You can automate repetitive commands. For example, suppose you have multiple text files and want to compress each of them into a separate file. You can use a loop such as
    for %f in (*.txt) do jar cvf %f.zip %f
    If there are many files to process, such an operation would be very tedious with a GUI. Many worthwhile tasks are never attempted by GUI users just because they don't know how to automate them.

Starting the Command Shell

Open the Run menu and type cmd(or command if you use a versionof Windows prior to XP): Ctrl+Esc R cmdEnter. The command shell window appears:

Windows Shell Tutorial (27)

The command shell has a rather primitive user interface.

  • A prompt shows the current directory, such as c:\windows.
  • You type a command and hit the Enter key.
  • The command is executed. Its output is displayed in the shell window.
  • Another prompt is then displayed, and the process repeats until you close the shell window.
Exercise 21
What prompt is displayed when you open up a command shell window?

Type the command

dir

followed by the Enter key into theshell window. You will see a listing of the files and directories in thecurrent directory.


Exercise 22
How many files are contained in the current directory? How many directories?

Now type the command

cd \

Don't forget hitting Enter.

Exercise 23
What does the prompt string look like now?

Exercise 24
What files and directories are contained in the root directory?

Now type

cd \yourname

As always, replace yournamewith your personal directory name. If your directory is contained in a driveother than C:, you first need to switch to the other drive by typing the driveletter followed by Enter, forexample

j:
cd \users\jqsmith

Next, type

cd tutorial
Exercise 25
What does the prompt string look like now?

Type

cd ..
Exercise 26
What does the prompt string look like now?

Finally, type

cd \tutorial
Exercise 27
What happens? Explain.

You have just learned the basic directory commands in the shell:

Typing cd plus a path changes the directory to the given path. Here apath can be relative to the current directory or absolute.Absolute paths always start with the root directory (\). Relative pathsbegin with a file name in the current directory.

There is one special file name that is very useful: the double period(..) refers to the parent directory of the current directory inthe directory tree, so that it is possible to go up the tree with relativepaths as well as down. Similarly, the filename. refers to the current directory, but thatabbreviation is not commonly needed.

Typing dir lists files in the current directory. You can also givedir a relative or absolute path, and it will display the appropriatedirectory, such as

dir ..\projects

Command Line Editing

Some people dislike using the command shell because it is tedious to reissuecommands that were mistyped. Fortunately, it is possible to retrieve and modifypreviously issued commands.

Hitting the Up and Down arrow keys cycles through the commandsthat you already typed.


Exercise 28
What command do you see when you hit the Up arrow key? What command do you see when you hit the Up arrow key again?

Windows Shell Tutorial (28) NOTE: If the arrow keys don't retrieve old commands and you run Windows XP, double-check that you are running cmd and not the older command shell. If you have an older version of Windows, you need to run the doskey program to enable command line editing. Simply run doskey after you open a command shell.
Exercise 29
Type c and the F8 key. Hit F8 repeatedly. What happens?

The F8 key performs a search of the previous commands that start withthe text you have already typed. This is often the fastest method forretrieving an old command.

You can use the cursor keys (Left,Right, Home, End) to edit the line that you called back.Move the cursor where you want it and insert or remove characters. If insertingcharacters types over existing text, hit the Ins key to switch from overtype mode toinsert mode.

Exercise 30
Type cd \windos (note the misspelling). After you get an error message, use command-line editing to fix it to cd \windows. What are the key strokes that you used?

Another very useful feature of the shell is filename completion. If you type a part of afilename and hit the Tab key, then thefirst matching file is displayed. Hitting Tab again cycles through all matchingcompletions.

Exercise 31
Type cd c:\w and hit Tab. What happens?
Windows Shell Tutorial (29) NOTE: Filename completion only works with Windows XP. It does not work with older versions of Windows.

Finally, if you look for a command and you don't find what you want, you canclear the command line and start over by hitting Ctrl+C. Indeed, thiscommand can be used to stop almost any action that is still in progress.

File Commands

The del command deletes a file.For example,

del sample.txt

deletes the file sample.txt.

Windows Shell Tutorial (30) NOTE:When you delete a file with the del command, it does not get moved into the trash can. It is deleted for good and cannot be retrieved.

To copy a file, use the copycommand, followed by the target file or directory. For example,

copy sample.txt sample.bak

copies the file sample.txt andnames the copy sample.bak.

Exercise 32
How would you achieve the same effect using the Explorer program?
copy sample.txt a:\

copies the file sample.txt intothe directory a:\. Because thetarget of the copy command is adirectory, the copied file keeps the same name.

To move a file, use the movecommand. For example,

move sample.txt a:\

moves the file sample.txt tothe directory a:\, removing theoriginal.

You can also use the movecommand to rename a file. The command

move sample.txt sample.bak

renames the file sample.txt tosample.bak.

Exercise 33
How would you achieve the same effect using the copy and del commands?

Directory Commands

The mkdir command makes adirectory. For example,

mkdir \yourname\homework1
cd \yourname\homework1
mkdir backup
Exercise 34
Execute these commands. What is the full path name of the backup directory that was created?

You remove a directory with the rmdir command. However, in order to beremovable, a directory must be completely empty. That is, you must first removeall files and directories that it contains.

Exercise 35
Execute thes command
rmdir \yourname\homework1
What error message do you get? How can you remove the directory?

Wildcards


Often when we want to copy files, we only want files of a certain type (thatis, with a certain file extension). For example, we may want to copy only textfiles (with extension .txt). Weuse the wildcard notation for thispurpose.

The command

copy *.txt a:\

copies all files whose names end with .txt to the a:\ directory.

Exercise 36
How would you copy all text files from the c:\windows directory to c:\yourname? Why is this a better solution than the one you found in exercise 19?
Exercise 37
What does the command
del c:\yourname\*.*
do?

The asterisk (*) in the entry *.txt stands for any sequence ofcharacters of any length. (Note how the file extension is given separately.)The other wildcard that is available is ?, which stands for any singlecharacter. Here are two more examples of the use of these wildcards:

The string s*.txt matches all files beginning with the letters and having the extension txt.

The string st??.ba? matches all files beginning with the lettersst whose filenames have four characters, and whose extensions consist ofthree characters beginning with ba.


Exercise 38
Use the dir command and wildcards to find all files in c:\windows that start with a w, have three letters, and whose extension is ini. What command did you issue, and what matches do you get?

Command-Line Options

Many shell commands take optionsthat modify their behavior.

For example, the dir commandhas an option /w that produces a"wide" listing, with several files in each line. The command is

dir /w

for a wide listing of the current directory, or

dir /w c:\windows

for a wide listing of the Windows directory.

Another useful option of the dir command is /p.

Exercise 39
Try the command dir c:\windows /p. What is the effect of the /p option?

You can combine multiple options:

dir /w /p c:\windows

In general, an option to a command starts with a forward slash,followed by a letter. Note that forward slashes (/) are entirely different fromfrom backslashes (\), which are path separators. Most commands have severaloptions, which you can find in the onlinehelp.

You can also get a brief description of a command and its options throughthe /? option, for example

del /?
Exercise 40
What are all options of the del command?
Windows Shell Tutorial (31)
NOTE: In Linux/Unix/Mac OS X, you use a dash, not a forward slash, for options. For example, ls -a.

Copying from and to the Shell Window

Sometimes, you need to copy information from a command shell window intoanother window (for example, to include output in a report or email).Unfortunately, this process is somewhat cumbersome.

  • Right-click on the command shell window. A context menu pops up.
  • Select the Mark option.
  • Use the mouse to select a rectangular area. (You can also use the cursor keys. Hit Down to move to the first line that you want to copy, then press Shift+Down to select the lines you want to copy.)
  • Hit Enter
  • Switch to another program (such as Notepad) and paste (Ctrl+V).

Obviously, this method can only be used to copy a single screen to Notepador another application. To get more than one screen, you will need to useredirection, which is described in the advanced lab.

Conversely, you may want to copy a command from another program (such as aweb browser) into the shell window. Copy the command, then right-click on theshell window and select the Pasteoption.

Exercise 41
Copy this command
dir /oen /p c:\windows
into the shell window and execute it. What happens?

Executing Programs

To execute a program from the command shell, you type the program name. Forexample, to launch the Explorer program, type

explorer

You can also provide command-line arguments. For example, to launch thenotepad program and edit aparticular file, simply specify the file name.

notepad c:\yourname\tutorial\sample.txt
Exercise 42
Execute the command
notepad c:\yourname\tutorial\myfile.txt
What happens? Explain.

When you give the name of a command, then Windows tries to find an programfile with that name. For example, when you type notepad, then Windows looks for the filenotepad.exe. It looks for theprogram file in the current directory, then in a set of standard places thatinclude the c:\windows and c:\windows\system32 directories. If theprogram file is not found, then an error message is displayed.

Exercise 43
Execute the command
notpad 
(Note the misspelling). What happens? Explain.

Sometimes, you need to execute a file that is not a part of the "standardplaces". For example, if you install the Java compiler, it is installed into adirectory such as c:\j2sdk\bin. Bydefault, Windows will not look inside that directory. You can, however, launchthe program by giving the full path name

c:\j2sdk\bin\javac MyProg.java

You will see a better solution in the advanced lab.

Exiting the shell

To close the shell window, type the command

exit

Alternatively, simply close the shell window.

Exercise 44
Execute the command
exit
What happens?
Windows Shell Tutorial (2024)
Top Articles
Can you reapply to a college after being accepted and declining?
How to Lube Mechanical Keyboard Switches: A Step-By-Step Guide - Hirosart
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 6142

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.