0% found this document useful (0 votes)
653 views23 pages

CMD Notes

Uploaded by

Sky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
653 views23 pages

CMD Notes

Uploaded by

Sky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Working with the Command-

Line Interface
• In this chapter, you will learn how to
• Explain the operation of the command-line interface
• Describe fundamental commands
Explain file manipulation
• Describe additional useful Windows commands
• Describe additional helpful macOS and Linux commands
• Explain scripting languages and platforms
The command prompt, like a GUI, is just another way to interface with a
computer. The command line interprets input and sends it to the OS in a form
the OS understands, and then shows the results. The tool that interprets input
is called the command-line interpreter, also known as the shell. The default
Windows shell is Command. On macOS and on most Linux distros, the default
shell is called bash.
While most operating systems have only one GUI, that’s not the case with the
shell. Every operating system has the ability to interface with different types of
shells. On macOS and Linux, it’s easy to use popular shells with names like Z
shell (zsh), Korn shell (ksh), and C shell (csh). In Windows you can use
PowerShell instead of Command. It’s a standard rite of nerd passage to start
experimenting with these alternative shells.
Accessing the Command-Line Interface in
Windows
A common way to access the command-line interface is through the
Start menu or the Start screen’s Search bar. Type cmd from the Start
screen. The Search option will appear with the full command. Press
ENTER.
A command prompt window pops up on your screen with a black
background and white text—welcome to the Windows command-line
interface. To close the CLI, you can either click the Close box in the
upper-right corner, as on any other window, or simply type exit and
press ENTER.
If you attempt to enter at the Windows command prompt a command
that requires elevated or administrative privileges, you receive a UAC
“Windows needs your permission to continue” dialog box. You can also
manually run a command with elevated privileges by right-clicking on a
command-prompt shortcut and then selecting Run as administrator. If
Windows prompts for the administrator password or credentials, enter
whatever is needed.
Accessing the Command-Line Interface in
macOS and Linu
The command line in macOS and the command line in Linux function
virtually identically. This isn’t too surprising given that both macOS and
Linux are based on UNIX. The terminal emulator in macOS has a specific
name, Terminal. The many distros of Linux use different emulators,
such as Konsole Terminal and GNOME Terminal. To make things easy,
we’ll use the command-line interface in Ubuntu Linux, conveniently
also Terminal. To open Terminal in macOS, either launch the Terminal
app from the Utilities folder (located in the Applications folder) or
activate Spotlight (COMMAND-SPACEBAR), type terminal, and press
enter to bring up the macOS Terminal
The Command Prompt
Regardless of what shell you use, the command prompt always focuses
on a specific folder, the working directory, usually indicated by the
prompt. The OS executes commands in the specified folder unless
otherwise directed. Here’s an example of focus. In Windows, if you see
a prompt that looks like the following line, you know that the focus is
on the root directory of the C: drive:
C:\>
In Windows, if you see a prompt that looks like Figure below, you know
that the focus is on the \Diploma\APLUS\ folder of the C: drive. The
trick to using a command line is first to focus the prompt on the drive
and folder where you want to work.
Closing the Terminal
Closing a command prompt is easy and is done the same way in
Windows, macOS, and Linux. At the prompt just type exit. The terminal
window will disappear.
Mastering Fundamental Commands
It’s time to try using the command line, but before you begin, a note of
warning is in order: the command-line interface is picky and
unforgiving. It will do what you say, not what you mean, so it always
pays to double-check that those are one and the same before you press
enter and commit the command. One careless keystroke can result in
the loss of crucial data, with no warning and no going back. In this
section, you’ll explore the structure of commands and then play with
basic commands to navigate and manipulate your OS’s folder structure.
Structure: Syntax and Switches
All commands in every command-line interface use a similar structure and
execute in the same way. You type the name of the command, followed by the
target of that command and any modifications of that command that you want to
apply. You can call up a modification by using an extra letter or number, called a
switch or option, which may follow either the command or the target, depending
on the command. The proper way to write a command is called its syntax. The key
with commands is that you can’t spell anything incorrectly or use a \ when the
syntax calls for a /. The command line is almost completely inflexible, so you have
to learn the correct syntax for each command.
[command] [target (if any)] [switches]
or [command] [switches] [target (if any)]
How do you know what switches are allowed? How do you know
whether the switches come before or after the target?
If you want to find out the syntax and switches used by a particular
command, in Windows type the command followed by /? to get help:
[command name] /?
When you are done reading the manual, press the q key to quit back to
the prompt.
Viewing Directory Contents: dir and ls
The Windows dir command and the macOS and Linux ls command
show you the contents of the working directory. If you’re like most
techs, you’ll use dir or ls more often than any other command at the
command prompt. When you open a command-line window in
Windows, it opens focused on your user folder. You will know this
because the prompt looks like C:\Users\User name>. By typing dir and
then pressing the enter key (remember that you must always press
enter to execute a command from the command line), you will see
something like this:
dir Command
When you type a simple dir command, you will see that some of the
entries
The dir command lists the creation date, creation time,
to tell you it is a folder, and the folder name. Now type the dir /w command. Note that the
dir /w command shows only the filenames, but they are arranged in four or five columns across your
screen. Finally, type dir /? to see the screen shown on your screen, which lists all possible switches for
the command.
Changing Directory Focus: The cd Command
The cd command works in every operating system, although there are
differences between Windows and macOS and Linux. You can use the
cd command to change the focus of the command prompt to a
different directory. To use the cd command, type cd followed by the
name of the directory on which you want the prompt to focus. For
example, in Windows, to go to the Obiwan directory in the root
directory, you type cd \obiwan and then press enter. If the system has
an Obiwan directory there, the prompt changes focus to that directory
and appears as C:\Obiwan>. If no Obiwan directory exists or if you
accidentally type something like obiwam, you get the error “The system
cannot find the path specified.”
To return to the root directory, type cd \ and press enter. You can use
the cd command to point the prompt to any directory. For example,
typing cd obiwan\my\hope from a C:\ prompt would change it to C:\
Obiwan\my\hope> —assuming, of course, that your system has a
directory called C:\Obiwan\my\hope.
Once the prompt has changed, type dir again. You should see a
different list of files and directories. Every directory holds different files
and subdirectories, so when you point the prompt to different
directories, the dir command shows you different contents.
Moving Between Drives in Windows
The cd command is not used to move between Windows’ drive letters. To
get the prompt to point to another drive (“point” is command-line
geekspeak for “switch its focus”), just type the drive letter and a colon. If
the prompt points at the C:\Users\mike directory and you want to see
what is on the USB thumb drive (E:), just type e: and the prompt will point
to the USB drive.
To return to the C: drive, just type c: and you’ll see the following:
Note that you return to the same directory you left. Just for fun, try typing
in a drive letter that you know doesn’t exist. For example, I know that my
system doesn’t have a W: drive. If I type in a nonexistent drive on a
Windows system, I get the following error:
The system cannot find the drive specified.
Making Directories: The md/mkdir
Command
Now that you have learned how to navigate in a command-prompt world, it’s time
to start making stuff, beginning with a new directory.
To make a directory, use the md command in Windows. Alternatively, you can use
the mkdir command, which works in all operating systems and is identical to md. In
Windows, to create a directory called practice under your user’s folder, for example,
open a new Command Prompt window or cd to your users folder at \Users\.<your
username> . You should see the prompt
C:Users\mike>_
Now that the prompt points to the C:\Users\mike directory, type md practice to
create the directory:
C:\Users\mike>md practice
Once you press enter, Windows executes the command, but it won’t
volunteer any information about what it did. You must use the dir
command to see that you have, in fact, created a new directory. Note
that the practice directory in this example is not listed last, as you
might expect.
Removing Directories: The rd/rmdir
Command
Removing subdirectories works exactly like making them. First, get to
the directory that contains the subdirectory you want to delete, and
then execute either the rmdir or rd command. Both of these commands
are functionally identical, but where they work is important. The rmdir
command works equally well in Windows, macOS, and Linux, but the rd
command only works in Windows.
Running a Program in Windows
To run a program from the Windows command line, simply change the
prompt focus to the folder where the program is located, type the
name of the program, and then press enter. Try this safe example. Go to
the C:\Windows\System32 folder—the exact name of this folder is
pretty standard on all Windows systems, but your mileage may vary.
Type dir /p to see the files one page at a time. You should see a file
called mmc.exe
Working with Files
This section deals with basic file manipulation. You will learn how to
look at, copy, move, rename, and delete files. The examples in this
section are based on a C: root directory with the following files and dir
C:\>dir
Because you probably don’t have a PC with these files and directories,
follow the examples but use what’s on your drive. In other words,
create your own folders and copy files to them from various folders
currently on your system.
Copying and Moving Files

You might also like