Sunteți pe pagina 1din 3

Command Line Interfaces

Key language:
command, switch, path, current directory, parent directory

Command Line Interfaces


Before the advent of the GUI, computers were controlled by typing commands into a Command Line Interface (CLI).
CLIs are still used a lot by network and system administrators because they allow a lot of control and flexibility over a
computer. In the right hands, CLIs are very powerful. Ask yourself: how would you do these things with a GUI:

 Make a list of all files in your Photos folder and save it in a text document
 Copy all files changed in the last week to your flash disk
 Delete all files ending in ".doc"
 Rename every file ending in .txt to .doc

These tasks are all possible, but with more than a few files they become time consuming and error prone. Command
line interfaces reduce these jobs to just one or two typed commands, even if operating on thousands of files at once.

Starting the Command Line prompt


To start the command line prompt (also called the terminal), click Start, Run, type cmd and press enter.

You will see a blinking white cursor and the current path (the folder you are in) on the left (your path may vary slightly
depending on your version of windows). In the command line, folders and files are separated by slash characters (\).

Information Technology in a Global Society www.itgstextbook.com Attribution-NonCommercial-2.0


Command Line Interface – Help Sheet - Common Tasks

Task Command Description


Getting help (all) Use the /? switch after most commands. For example dir /?
Clear the screen cls Type cls to get rid of any text in the command prompt
Navigating between cd Use cd to change the current directory to a different one. cd is always
folders followed by a folder name or path:

cd c:\users\gray\desktop

To change to the directory above the current one (the parent directory), use:

cd ..
Getting information dir Use the dir command to list the contents of the current directory. You can
about files and also use it to list the contents of a different directory by specifying the full
directories path:

dir c:\photos\hungary\F1
Deleting files del Del deletes files. You can use it with individual file names or wildcards, but
be extremely careful using wildcards – you may delete more than you
imagined! (Another good reason not to run as an administrator, to limit the
damage you could do)
Creating folders mkdir mkdir name1 makes a folder called name1 in the current directory.
Move files and move To move file1 into directory2, type: move file1 directory2
directories
Redirecting output >filename You can redirect output from commands so that instead of appearing on the
screen it appears elsewhere, such as in a file. This is a very powerful option.

To redirect output, use the greater than sign. For example, to redirect the
output of the dir command to a file called listing.txt:

dir >listing.txt

The screen will stay blank but the listing.txt file will appear containing the
command's output.
Operate on multiple * The asterisk character is used to represent "Any number of characters". The
files at once ? question mark character is used to represent "Any single character". Both are
(wildcards) used to operate on multiple files at once, and can be used with any command.
For example:

*.jpg matches any file that ends with .jpg


d* matches any file or folder that starts with the letter d
*volcano* matches any file that contains the word volcano anywhere in its
name
img_? Will match img_1, img_9, and img_z, but not img_11 or img_100

Information Technology in a Global Society www.itgstextbook.com Attribution-NonCommercial-2.0


Command Line Practical
As you complete these exercises, write the command used in the Answers column. This will help your revision later.

Task Answer
1. Download the CLI-exercise.zip file and extract it to N/A
your desktop.
2. Open a new command prompt. Change the current
directory to the CLI-exercise directory on the desktop
3. The folder contains a few PNG images, but these are
duplicates of the JPEG images. List the png images.
4. Delete all the files with the png extension using a
single command.
5. Make a new folder called elsalvador
6. Move all the image files from the exercise folder into
the elsalvador folder
7. Inside the elsalvador folder, make one new folder
called elpital and one new folder called misc
8. Move all files that start with el-pital- to the elpital
folder
9. Move all remaining files to the misc folder
10. Oops, a couple of guatemala images have found their
way into the misc folder. They have guatemala in their
file names. Delete them.
11. Now we want a list of all files in the cli-exercise
folder and all subfolders. You should be able to do this
with a single command. (You may need to use the
help function for the dir command)
12. Test the above command first to make sure it works,
then re-direct its output to a file called filelist.txt

Information Technology in a Global Society www.itgstextbook.com Attribution-NonCommercial-2.0

S-ar putea să vă placă și