What is a
Command Prompt?
In the
good old days before Microsoft Windows and Apple Mac OS came about, users
interacted with computers through a command prompt. This is a text-based
window for typing commands and receiving text-based output (see screen shot
above). Mouse and menu do not work here but the command line is a powerful interface
and is very convenient for running certain programs.
How do I
start a Command Prompt?
Different
versions of Windows differ, so here are a few possibilities.
Method 1.
From the Start Menu, select “Programs” or “Programs and Features”. Scroll
down to “Accessories” or “Windows systems”. Choose “Command Prompt”.
Method 2.
Press the Start button, type cmd in the search box, and click on Run or
Press Enter.
Method 3.
On Windows 8, Press Win-S, type cmd in the search box and select “Command
Prompt”.
A
text-based window like the above will pop up. By default this will have white
text on black background.
Below I
will use black on white to save the planet. You can try “color 17”, “color 4f”
etc. to get your favourite colours. Also you can right-click on the title bar
and choose Properties, to change the height and width of the window,
colour, font, etc.
Hard
drive and directory (cd, md)
Your
computer hard drive contains a number of directories and sub-directories
arranged
hierarchically.
When I start the command prompt, I am in the “C:\Windows\System32”
directory.
Some of the methods mentioned above will start in the “C:\Users\ziheng”
directory.
The C: drive is the default drive letter of the hard drive. If you have several
drives, they will be labelled D:, E:, etc. I use the C: drive for the OS
(operating system) and program files and keep my data files on the D: drive. To
change to the D: drive,
type D:
We then
change back to the C: drive.C: We use cd to change directory. To move one
level up,
type cd ..cd ..
Now the
prompt “C:\>” indicates we are in the root directory on the C: drive.
Absolute
vs. Relative Paths
When you
run cd to change directory, you can use an absolute path containing the entire
directory
structure
at once. An absolute path starts with a slash, which means we begin from the
root of the
hard
drive. Without the leading slash, the directory is relative to your current
directory. In the example here, “cd \” takes us to the root
directory
on the C: drive. We then use two relative steps to go into the directory
\Users\ziheng
directory.
All this can be achieved in one step: cd \Users\ziheng
Creating
a new directory (md or mkdir)
To make a
new directory called test (in the current
directory
ziheng), type md test or mkdir test
You can
always use Windows explorer to create new folders and copy or move files. For
this exercise, I have copied a few files into the test directory. Please do the
same yourself.
Getting
directory listings (dir)
To list
the contents of a directory, type dir In the output, the label <DIR>
indicates Folder1 is a directory while the others are files. The listing also
shows the date and time the file was created or last modified. The file sizes
(in bytes) are shown as well.
File
extensions and wildcards
In the
old times, a DOS/Windows file name (such as test1.txt) has two parts in the 8.3
format. The first part (test1) has up to 8 characters and the second part (txt)
is 3-characters long. The second part is called the file extension and
typically indicates the nature of the file. Thus test1.txt is a plain text file
while mb.exe is an executable file (a program). Modern versions of Window s
have relaxed those limits, but the idea of file extension is still used. Other
examples include doc or docx for Word documents, ppt or pptx for PowerPoint
files, pdf for PDF files, jpg or jpeg for jpeg files.
The
special characters * and ? can be used as wildcards when you specify file or
directory
names. The asterisk * means any number of any characters while ? means one character of any kind. Thus dir te* will list all the files and directories that start with “te”. dir *.txt lists all files that end with .txt (the text files).
Copying and deleting files
The
commands copy and del are for copying and deleting files.
copy
test1.txt test2.txt
dir
del
test2.txt
dir
Viewing
files on the screen
type
test1.txt
more
test1.txt
The
command type shows the content of the file on the screen. This works for plain
text files only, and rubbish and noise will pop up if the file is binary.
Binary files (such as executables, Word docs,etc.) are for the machine and not
for human consumption. The command more does the same as type except that it
pauses for every screen of output. Hit space to continue and q to quit.
Running
programs from the command line
Programs
are typically executable files (.exe files). You run the program by typing the
name of the program at the command line. See the discussion above about
absolute and relative paths. If you have trouble remembering the full absolute
path, you can find the executable file in Windows Explorer and drag it to the
command line. This will copy the file name onto the command line.
For
example, on my computer, the following command will start Microsoft Office
Excel (try
something
similar on your computer).
C:\Users\ziheng\test>"C:\Program
Files (x86)\Microsoft Office\OFFICE11\EXCEL.EXE"
The
following will run a program called BPP (file name bpp.exe), which is in the
directory
D:\Programs\bpp3.1
on the D: drive.
C:\Users\ziheng\test>D:\Programs\bpp3.1\bpp.exe
A few
tips
a) Use
slash \ on Windows to specify folders. Use backslash / on Mac OSX or UNIX.
b)
Commands and file and directory names are case-insensitive on Windows (MS-DOS),
while they are case-sensitive on Mac OSX or UNIX.
c) You
can type the first few letters of a file or directory name and then hit the Tab
key so that the OS will complete the name automatically. At the command line,
you can use , ¯ to cycle through old
commands, and then use ¬ and ® (and Ctrl-¬ and Ctrl-® , which move one word a
time) to edit the old command.
d) You
can use F7 to see a list of past commands and then , ¯ and Enter to select one.
e)
Surround in quotes a file or directory name with spaces. For example, dir
"My Documents". However, this may not always work. You will make your
life easier if you use English letters, numbers, and underscores only in your
file names, and avoid space, non-English symbols etc.
f) When a
file or directory is deleted in the command line, it is deleted permanently and
is not moved into the Recycle Bin.
g)
Windows Explorer by default hides file extensions for known file types. To show
the file extension, choose “Windows Explorer - Tools - Folder options – View”
and un-tick “Hide extensions for known file types”.
Related searches
what is command prompt in windows 10
what is command prompt in java
what is command prompt in linux
what is command prompt in python
command prompt commands list
what is command prompt in laptop
what is command prompt on mac
how to open command prompt
command prompt download
command prompt commands
command prompt codes
command prompt shortcut
command prompt online
command prompt commands list
command prompt windows 10
command prompt open
0 Comments
If you have any doubts. Please let me know